public static void SetWeaponInSlot(this PlayerEntity playerEntity, EWeaponBagIndex bagIndex, EWeaponSlotType slot, int weaponEntityId) { var weaponBag = playerEntity.GetWeaponBagComponent((EWeaponBagIndex)playerEntity.bagState.CurBag); if (null != weaponBag) { switch (slot) { case EWeaponSlotType.PrimeWeapon: weaponBag.PrimeWeapon = weaponEntityId; break; case EWeaponSlotType.SecondaryWeapon: weaponBag.SecondaryWeapon = weaponEntityId; break; case EWeaponSlotType.PistolWeapon: weaponBag.PistolWeapon = weaponEntityId; break; case EWeaponSlotType.MeleeWeapon: weaponBag.MeleeWeapon = weaponEntityId; break; case EWeaponSlotType.ThrowingWeapon: weaponBag.ThrowingWeapon = weaponEntityId; break; case EWeaponSlotType.TacticWeapon: weaponBag.TacticWeapon = weaponEntityId; break; } } else { Logger.ErrorFormat("no bag in index ", (EWeaponBagIndex)playerEntity.bagState.CurBag); } }
public static bool TryGetWeapon(this PlayerEntity playerEntity, Contexts contexts, EWeaponBagIndex bagIndex, EWeaponSlotType slot, out WeaponEntity weaponEntity) { if (slot <= EWeaponSlotType.None || bagIndex <= EWeaponBagIndex.None || bagIndex >= EWeaponBagIndex.Length || slot >= EWeaponSlotType.Length) { weaponEntity = new WeaponEntity(); return(false); } var entityId = GetWeaponInSlot(playerEntity, slot); if (!entityId.HasValue) { weaponEntity = new WeaponEntity(); return(false); } weaponEntity = contexts.weapon.GetEntityWithEntityKey(new EntityKey(entityId.Value, (short)EEntityType.Weapon)); return(null != weaponEntity); }
public static void RemoveWeaponEntity(this PlayerEntity playerEntity, Contexts contexts, EWeaponBagIndex bagIndex, EWeaponSlotType slotIndex) { WeaponEntity weaponEntity; if (!playerEntity.TryGetWeapon(contexts, out weaponEntity)) { return; } if (SharedConfig.IsServer) { weaponEntity.RemoveOwner(); } playerEntity.SetWeaponInSlot(slotIndex, 0); }
public static WeaponBagComponent GetWeaponBagComponent(this PlayerEntity playerEntity, EWeaponBagIndex index) { switch (index) { case EWeaponBagIndex.First: return(playerEntity.firstWeaponBag); case EWeaponBagIndex.Second: return(playerEntity.secondaryWeaponBag); case EWeaponBagIndex.Third: return(playerEntity.thirdWeaponBag); case EWeaponBagIndex.Forth: return(playerEntity.forthWeaponBag); case EWeaponBagIndex.Fifth: return(playerEntity.fifthWeaponBag); } return(null); }