void TryPasteLock(BaseCombatEntity lockableEntity, IDictionary <string, object> structure) { BaseEntity lockentity = null; if (structure.ContainsKey("codelock")) { lockentity = GameManager.server.CreateEntity("build/locks/lock.code", Vector3.zero, new Quaternion()); lockentity.OnDeployed(lockableEntity); var code = (string)structure["codelock"]; if (!string.IsNullOrEmpty(code)) { var @lock = lockentity.GetComponent <CodeLock>(); codelock.SetValue(@lock, (string)structure["codelock"]); @lock.SetFlag(BaseEntity.Flags.Locked, true); } } else if (structure.ContainsKey("keycode")) { lockentity = GameManager.server.CreateEntity("build/locks/lock.key", Vector3.zero, new Quaternion()); lockentity.OnDeployed(lockableEntity); var code = Convert.ToInt32(structure["keycode"]); var @lock = lockentity.GetComponent <KeyLock>(); if ((code & 0x80) != 0) { // Set the keycode only if that lock had keys before. Otherwise let it be random. keycode.SetValue(@lock, (code & 0x7F)); firstKeyCreated.SetValue(@lock, true); @lock.SetFlag(BaseEntity.Flags.Locked, true); } } if (lockentity) { lockentity.gameObject.Identity(); lockentity.SetParent(lockableEntity, "lock"); lockentity.Spawn(true); lockableEntity.SetSlot(BaseEntity.Slot.Lock, lockentity); } }
void TryPasteLock(BaseCombatEntity lockableEntity, IDictionary<string, object> structure) { BaseEntity lockentity = null; if (structure.ContainsKey("codelock")) { lockentity = GameManager.server.CreateEntity("build/locks/lock.code", Vector3.zero, new Quaternion()); lockentity.OnDeployed(lockableEntity); var code = (string)structure["codelock"]; if (!string.IsNullOrEmpty(code)) { var @lock = lockentity.GetComponent<CodeLock>(); codelock.SetValue(@lock, (string)structure["codelock"]); @lock.SetFlag(BaseEntity.Flags.Locked, true); } } else if (structure.ContainsKey("keycode")) { lockentity = GameManager.server.CreateEntity("build/locks/lock.key", Vector3.zero, new Quaternion()); lockentity.OnDeployed(lockableEntity); var code = Convert.ToInt32(structure["keycode"]); var @lock = lockentity.GetComponent<KeyLock>(); if ((code & 0x80) != 0) { // Set the keycode only if that lock had keys before. Otherwise let it be random. keycode.SetValue(@lock, (code & 0x7F)); firstKeyCreated.SetValue(@lock, true); @lock.SetFlag(BaseEntity.Flags.Locked, true); } } if (lockentity) { lockentity.gameObject.Identity(); lockentity.SetParent(lockableEntity, "lock"); lockentity.Spawn(true); lockableEntity.SetSlot(BaseEntity.Slot.Lock, lockentity); } }