First Machine Age's Mods (Combined repo.)
Revisão | 124616167119a9d0ef61f449e74845e4fa50bc66 (tree) |
---|---|
Hora | 2019-11-18 08:28:10 |
Autor | melchior <melchior@user...> |
Commiter | melchior |
W.I.P. #6: Almost working
@@ -293,20 +293,19 @@ namespace FirstMachineAge | ||
293 | 293 | |
294 | 294 | public void ApplyLock(BlockSelection blockSel, IPlayer player, ItemSlot itemSlot, string desc = null) |
295 | 295 | { |
296 | - bool success = true; | |
296 | + bool commitACN = true; | |
297 | 297 | |
298 | 298 | GenericLock theLock = itemSlot.Itemstack.Item as GenericLock; |
299 | 299 | string material = theLock.Variant[_lockMaterial]; |
300 | 300 | |
301 | 301 | BlockPos blockPos = blockSel.Position.Copy( ); |
302 | 302 | |
303 | - | |
304 | 303 | //TODO: Adjust position(s) with N block high doors, but player selected 'lower' part... |
305 | 304 | AdjustBlockPostionForMultiBlockStructure(ref blockPos); |
306 | 305 | |
307 | 306 | //Client path only updates local cache? |
308 | 307 | if (CoreAPI.Side.IsClient( )) { |
309 | - AddLock_ClientCache(blockPos, theLock); | |
308 | + AddLock_ClientCache(blockPos, theLock, player); | |
310 | 309 | return; |
311 | 310 | } |
312 | 311 |
@@ -324,8 +323,10 @@ namespace FirstMachineAge | ||
324 | 323 | newLockACN.CombinationCode = theLock.CombinationCode(itemSlot); |
325 | 324 | newLockACN.Tier = theLock.LockTier; |
326 | 325 | |
327 | - if (newLockACN.CombinationCode == null) { | |
326 | + if (newLockACN.CombinationCode == null) | |
327 | + { | |
328 | 328 | Mod.Logger.Warning("Undefined Combination # for existant lock - can't apply!"); |
329 | + commitACN = false; | |
329 | 330 | } |
330 | 331 | } |
331 | 332 |
@@ -342,27 +343,23 @@ namespace FirstMachineAge | ||
342 | 343 | //Mark slot dirty? |
343 | 344 | } |
344 | 345 | |
345 | - if (Server_ACN.ContainsKey(chunkPos)) { | |
346 | - Server_ACN[chunkPos].Entries.Add(blockPos, newLockACN); | |
346 | + if (Server_ACN.ContainsKey(chunkPos) && commitACN) | |
347 | + { | |
348 | + Mod.Logger.Debug("Appending to ChunkACNodes at {0}", chunkPos); | |
349 | + Server_ACN[chunkPos].Entries.Add(blockPos, newLockACN); | |
350 | + Server_ACN[chunkPos].Altered = true; | |
347 | 351 | } |
348 | 352 | else |
349 | 353 | { |
350 | 354 | Mod.Logger.Debug("Created ChunkACNodes for {0}", chunkPos); |
351 | 355 | Server_ACN.Add(chunkPos, new ChunkACNodes(chunkPos)); |
352 | 356 | Server_ACN[chunkPos].Entries.Add(blockPos, newLockACN); |
357 | + Server_ACN[chunkPos].Altered = true; | |
353 | 358 | } |
354 | - | |
355 | - if (success) { | |
356 | - //Mark this host chunk had an ACL added, thus altered. | |
357 | - Server_ACN[chunkPos].Altered = true; | |
358 | - | |
359 | - //Send message to player that object was locked with X type lock (and combo / key#) | |
360 | - //Send out ACN update selective broadcast msg... | |
361 | - UpdateBroadcast(serverPlayer, blockPos, newLockACN ); | |
362 | - } | |
363 | - | |
364 | - | |
365 | - | |
359 | + | |
360 | + //Send message to player that object was locked with X type lock (and combo / key#) | |
361 | + //Send out ACN update selective broadcast msg... | |
362 | + if (commitACN) UpdateBroadcast(serverPlayer, blockPos, newLockACN ); | |
366 | 363 | |
367 | 364 | } |
368 | 365 |
@@ -110,7 +110,9 @@ | ||
110 | 110 | <None Include="assets\fma\shapes\item\access_controls\key1.json"> |
111 | 111 | <CopyToOutputDirectory>Always</CopyToOutputDirectory> |
112 | 112 | </None> |
113 | - <None Include="assets\fma\shapes\item\access_controls\barrel_lock.json" /> | |
113 | + <None Include="assets\fma\shapes\item\access_controls\barrel_lock.json"> | |
114 | + <CopyToOutputDirectory>Always</CopyToOutputDirectory> | |
115 | + </None> | |
114 | 116 | </ItemGroup> |
115 | 117 | <ItemGroup> |
116 | 118 | <ProjectReference Include="..\FirstMachineAge_Common\Common.csproj"> |
@@ -139,18 +139,7 @@ namespace FirstMachineAge | ||
139 | 139 | targetChunk = ServerAPI.WorldManager.GetChunk(chunkPos.X, chunkPos.Y, chunkPos.Z); |
140 | 140 | } |
141 | 141 | |
142 | - //TODO: Remove when bug in API is fixed! | |
143 | - if (targetChunk is ServerChunk) | |
144 | - { | |
145 | - ServerChunk srvChunk = targetChunk as ServerChunk; | |
146 | - | |
147 | - if (srvChunk.ServerSideModdata == null) | |
148 | - { | |
149 | - srvChunk.ServerSideModdata = new Dictionary<string, byte[ ]>( ); | |
150 | - } | |
151 | - | |
152 | - data = srvChunk.GetServerModdata(_AccessControlNodesKey); | |
153 | - } | |
142 | + | |
154 | 143 | |
155 | 144 | if (data != null && data.Length > 0) { |
156 | 145 | #if DEBUG |
@@ -163,7 +152,7 @@ namespace FirstMachineAge | ||
163 | 152 | } |
164 | 153 | else if (targetChunk != null){ |
165 | 154 | #if DEBUG |
166 | - Mod.Logger.VerboseDebug("Absent ACN structures for chunk: {0}", chunkPos); | |
155 | + Mod.Logger.VerboseDebug("Absent ACN structures for chunk: {0} !", chunkPos); | |
167 | 156 | #endif |
168 | 157 | //Setup new AC Node list for this chunk. |
169 | 158 | ChunkACNodes newAcNodes = new ChunkACNodes( ); |
@@ -189,6 +178,9 @@ namespace FirstMachineAge | ||
189 | 178 | { |
190 | 179 | Mod.Logger.Debug("ACN Data persistence routines activated"); |
191 | 180 | |
181 | + var alteredCount = Server_ACN.Count(ac => ac.Value.Altered == true); | |
182 | + if (alteredCount > 0) Mod.Logger.Debug("There are {0} unsaved chunk Nodes ( should be zero !)", alteredCount); | |
183 | + | |
192 | 184 | foreach (var entry in this.Server_ACN) { |
193 | 185 | if (entry.Value.Altered == false) continue; |
194 | 186 |
@@ -200,16 +192,6 @@ namespace FirstMachineAge | ||
200 | 192 | |
201 | 193 | byte[ ] data = SerializerUtil.Serialize<ChunkACNodes>(entry.Value); |
202 | 194 | |
203 | - //TODO: Remove when bug in API is fixed! | |
204 | - if (targetChunk is ServerChunk) { | |
205 | - ServerChunk srvChunk = targetChunk as ServerChunk; | |
206 | - | |
207 | - if (srvChunk.ServerSideModdata == null) { | |
208 | - srvChunk.ServerSideModdata = new Dictionary<string, byte[ ]>( ); | |
209 | - } | |
210 | - | |
211 | - data = srvChunk.GetServerModdata(_AccessControlNodesKey); | |
212 | - } | |
213 | 195 | |
214 | 196 | targetChunk.SetServerModdata(_AccessControlNodesKey, data); |
215 | 197 | } |
@@ -242,7 +224,7 @@ namespace FirstMachineAge | ||
242 | 224 | /// </summary> |
243 | 225 | /// <param name="pos">Block Position.</param> |
244 | 226 | /// <param name="theLock">The subject lock.</param> |
245 | - protected void AddLock_ClientCache(BlockPos pos, GenericLock theLock) | |
227 | + protected void AddLock_ClientCache(BlockPos pos, GenericLock theLock, IPlayer owner) | |
246 | 228 | { |
247 | 229 | if (this.Client_LockLookup.ContainsKey(pos.Copy( ))) { |
248 | 230 | Mod.Logger.Warning("Can't overwrite cached lock entry located: {0}", pos); |
@@ -251,6 +233,7 @@ namespace FirstMachineAge | ||
251 | 233 | var lockStateNode = new LockCacheNode( ); |
252 | 234 | |
253 | 235 | lockStateNode.Tier = theLock.LockTier; |
236 | + lockStateNode.OwnerName = owner.PlayerName; | |
254 | 237 | |
255 | 238 | switch (theLock.LockStyle) { |
256 | 239 | case LockKinds.None: |
@@ -327,7 +310,7 @@ namespace FirstMachineAge | ||
327 | 310 | |
328 | 311 | if (networkMessage != null && networkMessage.LockStatesByBlockPos != null) { |
329 | 312 | #if DEBUG |
330 | - Mod.Logger.VerboseDebug("ACN Rx from Server; {0} nodes", networkMessage.LockStatesByBlockPos.Count); | |
313 | + Mod.Logger.VerboseDebug("ACN Rx from Server; {0} AC-nodes", networkMessage.LockStatesByBlockPos.Count); | |
331 | 314 | #endif |
332 | 315 | |
333 | 316 | foreach (var update in networkMessage.LockStatesByBlockPos) { |
@@ -377,7 +360,7 @@ namespace FirstMachineAge | ||
377 | 360 | |
378 | 361 | private void UpdateBroadcast(IServerPlayer byPlayer, BlockPos blockPos, AccessControlNode updatedLock) |
379 | 362 | { |
380 | - | |
363 | + Mod.Logger.Debug("Broadcast single ACN @{0} ", blockPos); | |
381 | 364 | foreach (IServerPlayer tgtPlayer in ServerAPI.World.AllOnlinePlayers) |
382 | 365 | { |
383 | 366 | LockStatusList specificLSL = ComputeLSLFromACN(blockPos, updatedLock, tgtPlayer); |
@@ -410,7 +393,7 @@ namespace FirstMachineAge | ||
410 | 393 | Mod.Logger.VerboseDebug("Portunus re-trigger [{0}]", portunus_thread.ThreadState); |
411 | 394 | #endif |
412 | 395 | |
413 | - if (portunus_thread.ThreadState.HasFlag(ThreadState.Unstarted) ){ | |
396 | + if (portunus_thread.ThreadState.HasFlag(ThreadState.Unstarted) ){ | |
414 | 397 | portunus_thread.Start( ); |
415 | 398 | } |
416 | 399 | else if (portunus_thread.ThreadState.HasFlag(ThreadState.WaitSleepJoin)) { |
@@ -468,8 +451,10 @@ namespace FirstMachineAge | ||
468 | 451 | } |
469 | 452 | |
470 | 453 | //Persist & SAVE-COMMIT Altered ACNs ! |
454 | + var alteredCount = Server_ACN.Count(ac => ac.Value.Altered == true); | |
455 | + if (alteredCount > 0) Mod.Logger.Debug("There are {0} altered chunk Nodes to persist", alteredCount); | |
471 | 456 | |
472 | - foreach (var alteredEntry in Server_ACN.TakeWhile(node => node.Value.Altered == true)) { | |
457 | + foreach (var alteredEntry in Server_ACN.Where(node => node.Value.Altered == true).ToList()) { | |
473 | 458 | byte[ ] data = SerializerUtil.Serialize<ChunkACNodes>(alteredEntry.Value); |
474 | 459 | |
475 | 460 | IServerChunk updatingChunk = ServerAPI.WorldManager.GetChunk(alteredEntry.Key.X, alteredEntry.Key.Y, alteredEntry.Key.Z); |
@@ -477,7 +462,7 @@ namespace FirstMachineAge | ||
477 | 462 | updatingChunk.SetServerModdata(_AccessControlNodesKey, data); |
478 | 463 | |
479 | 464 | alteredEntry.Value.Altered = false; |
480 | - Mod.Logger.VerboseDebug("Stored ACN for pos {0}", alteredEntry.Key); | |
465 | + Mod.Logger.VerboseDebug("Stored ACN(s) for pos {0}", alteredEntry.Key); | |
481 | 466 | } |
482 | 467 | |
483 | 468 | //Then sleep until interupted again, and repeat |
@@ -516,15 +501,18 @@ namespace FirstMachineAge | ||
516 | 501 | |
517 | 502 | case LockKinds.Classic: |
518 | 503 | lcn.LockState = locked ? LockStatus.Locked : LockStatus.Unlocked; |
504 | + lcn.OwnerName = ServerAPI.World.PlayerByUid(entry.Value.OwnerPlayerUID).PlayerName; | |
519 | 505 | break; |
520 | 506 | |
521 | 507 | case LockKinds.Combination: |
522 | 508 | lcn.LockState = locked ? LockStatus.ComboUnknown : LockStatus.ComboKnown; |
509 | + lcn.OwnerName = ServerAPI.World.PlayerByUid(entry.Value.OwnerPlayerUID).PlayerName; | |
523 | 510 | lcn.Tier = entry.Value.Tier; |
524 | 511 | break; |
525 | 512 | |
526 | 513 | case LockKinds.Key: |
527 | 514 | lcn.LockState = locked ? LockStatus.KeyNope : LockStatus.KeyHave; |
515 | + lcn.OwnerName = ServerAPI.World.PlayerByUid(entry.Value.OwnerPlayerUID).PlayerName; | |
528 | 516 | break; |
529 | 517 | } |
530 | 518 |
@@ -548,18 +536,21 @@ namespace FirstMachineAge | ||
548 | 536 | |
549 | 537 | case LockKinds.Classic: |
550 | 538 | lcn.LockState = locked ? LockStatus.Locked : LockStatus.Unlocked; |
539 | + lcn.OwnerName = ServerAPI.World.PlayerByUid(updatedLock.OwnerPlayerUID).PlayerName; | |
551 | 540 | break; |
552 | 541 | |
553 | 542 | case LockKinds.Combination: |
554 | 543 | lcn.LockState = locked ? LockStatus.ComboUnknown : LockStatus.ComboKnown; |
544 | + lcn.OwnerName = ServerAPI.World.PlayerByUid(updatedLock.OwnerPlayerUID).PlayerName; | |
555 | 545 | lcn.Tier = updatedLock.Tier; |
556 | 546 | break; |
557 | 547 | |
558 | 548 | case LockKinds.Key: |
559 | 549 | lcn.LockState = locked ? LockStatus.KeyNope : LockStatus.KeyHave; |
550 | + lcn.OwnerName = ServerAPI.World.PlayerByUid(updatedLock.OwnerPlayerUID).PlayerName; | |
560 | 551 | break; |
561 | - } | |
562 | - | |
552 | + } | |
553 | + | |
563 | 554 | LockStatusList singleLockState = new LockStatusList(blockPos, lcn); |
564 | 555 | |
565 | 556 | return singleLockState; |
@@ -634,7 +625,7 @@ namespace FirstMachineAge | ||
634 | 625 | { |
635 | 626 | var keyId = GenericKey.KeyID(slot.Itemstack); |
636 | 627 | //PlayerUID ? |
637 | - keyIds.Add(keyId); | |
628 | + if (keyId > 0) keyIds.Add(keyId); | |
638 | 629 | } |
639 | 630 | } |
640 | 631 |
@@ -83,13 +83,16 @@ namespace FirstMachineAge | ||
83 | 83 | |
84 | 84 | if (acm != null) |
85 | 85 | { |
86 | - LockStatus lockstate = acm.LockState(pos.Copy( ), forPlayer); | |
86 | + BlockPos adjPos = pos.Copy( ); | |
87 | + acm.AdjustBlockPostionForMultiBlockStructure(ref adjPos); | |
88 | + | |
89 | + LockStatus lockstate = acm.LockState(adjPos, forPlayer); | |
87 | 90 | |
88 | 91 | if (lockstate != LockStatus.None) |
89 | 92 | { |
90 | - var locktier = acm.LockTier(pos.Copy( ), forPlayer); | |
91 | - var lockowner = acm.LockOwnerName(pos.Copy( ), forPlayer); | |
92 | - lockInfo.AppendFormat("LockState: {0}, Owner: {1} - Tier: {2}", lockstate,lockowner, locktier); | |
93 | + var locktier = acm.LockTier(adjPos, forPlayer); | |
94 | + var lockowner = acm.LockOwnerName(adjPos, forPlayer); | |
95 | + lockInfo.AppendFormat("LockStatus: {0}, Owner: {1} @ Tier:{2}", lockstate,lockowner, locktier); | |
93 | 96 | |
94 | 97 | return lockInfo.ToString( ); |
95 | 98 | } |
@@ -91,12 +91,12 @@ namespace FirstMachineAge | ||
91 | 91 | [ProtoContract] |
92 | 92 | public class AccessEntry |
93 | 93 | { |
94 | - [ProtoMember(0)] | |
94 | + [ProtoMember(1)] | |
95 | 95 | public string PlayerUID; |
96 | 96 | |
97 | 97 | //Access type; Player or Group ? |
98 | 98 | |
99 | - [ProtoMember(1)] | |
99 | + [ProtoMember(2)] | |
100 | 100 | public int? GroupID; |
101 | 101 | |
102 | 102 |
@@ -124,12 +124,12 @@ namespace FirstMachineAge | ||
124 | 124 | } |
125 | 125 | else if (this.LockStyle == LockKinds.Key) |
126 | 126 | { |
127 | - var keyId = KeyID(slot); | |
127 | + //var keyId = KeyID(slot); | |
128 | 128 | |
129 | - if (keyId.HasValue == false) | |
130 | - { | |
131 | - GenerateKeyId(slot, this); | |
132 | - } | |
129 | + //if (keyId.HasValue == false) | |
130 | + //{ | |
131 | + //GenerateKeyId(slot, this); | |
132 | + //} | |
133 | 133 | } |
134 | 134 | |
135 | 135 | } |