/// <summary> /// API:parts /// </summary> /// <param name="slot"></param> /// <param name="id"></param> /// <returns></returns> public bool SetWeaponPart(EWeaponSlotType slot, int id) { var agent = GetWeaponAgent(slot); if (!agent.IsValid()) { return(false); } WeaponPartsStruct lastParts = agent.BaseComponent.CreateParts(); int realAttachId = WeaponUtil.GetRealAttachmentId(id, agent.ResConfig.Id); bool match = SingletonManager.Get <WeaponPartsConfigManager>().IsPartMatchWeapon(realAttachId, agent.ResConfig.Id); if (!match) { return(false); } var attachments = WeaponPartUtil.ModifyPartItem( agent.BaseComponent.CreateParts(), SingletonManager.Get <WeaponPartsConfigManager>().GetPartType(realAttachId), realAttachId); agent.BaseComponent.ApplyParts(attachments); if (slot == HeldSlotType) { RefreshHeldWeaponAttachment(); } WeaponPartsRefreshStruct refreshData = new WeaponPartsRefreshStruct(); refreshData.weaponInfo = agent.ComponentScan; refreshData.slot = slot; refreshData.oldParts = lastParts; refreshData.newParts = agent.BaseComponent.CreateParts(); RefreshModelWeaponParts(refreshData); return(true); }
private void LoadWeaponObject(SceneObjectEntity sceneObjectEntity) { var weapon = sceneObjectEntity.weaponObject; var allConfigs = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(weapon.ConfigId); if (allConfigs == null) { return; } if (WeaponUtil.IsC4p(weapon.ConfigId)) { sceneObjectEntity.AddBombSound(DateTime.Now.Ticks / 10000L, 0); } var avatarSize = allConfigs.WeaponDefaultAvartar.Size; if (avatarSize != 1) { sceneObjectEntity.AddSize(avatarSize); } weapon.ApplyParts(allConfigs.DefaultParts); Logger.InfoFormat("***Load weapon {0} from object***", allConfigs.S_Id); LoadWeaponObject(sceneObjectEntity, allConfigs.NewWeaponCfg); }
public override void DoAction(IEventArgs args) { if (string.IsNullOrEmpty(player)) { player = "current"; } FreeRuleEventArgs fr = (FreeRuleEventArgs)args; PlayerEntity playerEntity = (PlayerEntity)fr.GetEntity(player); IParable item = args.GetUnit("item"); if (playerEntity != null && item != null) { SimpleProto message = FreePool.Allocate(); message.Key = FreeMessageConstant.ChangeAvatar; int itemId = FreeUtil.ReplaceInt("{item.itemId}", args); playerEntity.WeaponController().PickUpWeapon(WeaponUtil.CreateScan(itemId)); //playerEntity.bag.Bag.SetWeaponBullet(30); //playerEntity.bag.Bag.SetReservedCount(100); message.Ins.Add(itemId); message.Ks.Add(2); playerEntity.network.NetworkChannel.SendReliable((int)EServer2ClientMessage.FreeData, message); } }
public static TeamMember generateNewTeamMember() { WeaponDefinition primary = WeaponUtil.getWeapon("M16A3", RarityObject.Rarity.COMMON); WeaponDefinition secondary = WeaponUtil.getWeapon("M9A1", RarityObject.Rarity.UNCOMMON); //load the name json object TextAsset namesJson = Resources.Load <TextAsset>(memberNamesPath); //deserialize the name json into an object MemberNames memberNames = JsonConvert.DeserializeObject <MemberNames>(namesJson.text); string fName; if (Random.Range(0, 1) < 0.5) { fName = memberNames.maleNames[Random.Range(0, memberNames.maleNames.Count)]; } else { fName = memberNames.femaleNames[Random.Range(0, memberNames.maleNames.Count)]; } string sName = memberNames.surnames[Random.Range(0, memberNames.maleNames.Count)]; return(new TeamMember(Random.Range(0, 15), fName, sName, primary, secondary, primary, secondary)); }
private void RefreshModelWeaponParts(WeaponPartsRefreshStruct refreshData) { if (refreshData.armInPackage) { var avatarId = refreshData.weaponInfo.AvatarId; if (avatarId < 1) { avatarId = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(refreshData.weaponInfo.ConfigId).AvatorId; } if (WeaponUtil.IsC4p(refreshData.weaponInfo.ConfigId)) { OverrideBagTactic = refreshData.weaponInfo.ConfigId; weaponInteract.UnmountC4(); } else { RelatedAppearence.MountWeaponInPackage(refreshData.slot.ToWeaponInPackage(), avatarId); } } weaponInteract.ModelRefreshWeaponParts(refreshData.weaponInfo.ConfigId, refreshData.slot, refreshData.oldParts, refreshData.newParts); if (refreshData.lastWeaponKey.IsValid()) { if (refreshData.slot == HeldSlotType) { RefreshHeldWeapon(); } ////var handler = slotsAux.FindHandler(refreshData.slot); //if (refreshData.lastWeaponId != refreshData.weaponInfo.ConfigId) // handler.RecordLastWeaponId(refreshData.lastWeaponId); } }
public static void AttachWeaponComponents(Contexts contexts, PlayerEntity playerEntity) { WeaponEntityFactory.EntityIdGenerator = contexts.session.commonSession.EntityIdGenerator; WeaponEntityFactory.WeaponContxt = contexts.weapon; var emptyScan = WeaponUtil.CreateScan(WeaponUtil.EmptyHandId); // playerEntity.RemoveWeaponComponents(); var greandeIds = WeaponUtil.ForeachFilterGreandeIds(); // WeaponUtil.EmptyWeapon = WeaponEntityFactory.CreateEmpty(emptyScan); playerEntity.AttachPlayerWeaponBags(); // playerEntity.AttachPlayerAux(); playerEntity.AttachGrenadeCacheData(greandeIds); playerEntity.AttachPlayerAmmu(); playerEntity.playerWeaponAuxiliary.HasAutoAction = true; playerEntity.AttachPlayerCustomize(); playerEntity.AddPlayerWeaponServerUpdate(); playerEntity.AttachWeaponComponentBehavior(contexts, greandeIds); // var entityId = contexts.session.commonSession.EntityIdGenerator.GetNextEntityId(); // playerEntity.AddEmptyHand(); //playerEntity.emptyHand.EntityId = emptyHandEntity.entityKey.Value.EntityId; //playerEntity.RefreshOrientComponent(null); //playerEntity.AddWeaponAutoState(); }
public bool DestroyWeapon(EWeaponSlotType slotType, int bagIndex, bool interrupt = true) { var weaponAgent = GetWeaponAgent(slotType, bagIndex); if (!weaponAgent.IsValid()) { return(false); } if (WeaponUtil.IsC4p(weaponAgent.ConfigId)) { RelatedAppearence.RemoveC4(); } weaponAgent.ReleaseWeapon(); //移除武器背包操作 playerWeaponAgent.RemoveBagWeapon(slotType, bagIndex); if (IsHeldBagSlotType(slotType, bagIndex)) { SetHeldSlotTypeProcess(EWeaponSlotType.None); } if (bagIndex == -1 || bagIndex == HeldBagPointer) { WeaponInPackage pos = slotType.ToWeaponInPackage(); RelatedAppearence.UnmountWeaponInPackage(pos); if (interrupt) { Interrupt(); } } return(true); }
public void TryHoldGrenade(bool autoStuff = true, bool tryArm = true) { var weaponAgent = this[EWeaponSlotType.ThrowingWeapon]; if (autoStuff && weaponAgent.IsValid()) { return; } int nextId = _grenadeHandler.FindUsable(autoStuff); if (nextId < 0 || weaponAgent.ConfigId == nextId) { return; } WeaponPartsRefreshStruct refreshParams = new WeaponPartsRefreshStruct(); WeaponEntity newEntity = weaponAgent.ReplaceWeapon(Owner, WeaponUtil.CreateScan(nextId), ref refreshParams); SyncBagWeapon(EWeaponSlotType.ThrowingWeapon, newEntity.entityKey.Value); RefreshModelWeaponParts(refreshParams); if (tryArm) { TryArmWeaponImmediately(EWeaponSlotType.ThrowingWeapon); } }
public void OnGamePlay() { if (GameRules.IsChicken(_contexts.session.commonSession.RoomInfo.ModeId)) { return; } if (_contexts.session.commonSession.FreeArgs.Rule.ServerTime - _lastTime < CheckLimitTime) { return; } _list.Clear(); _list.AddRange(_group.GetEntities()); if (_list.Count > _maxCount) { _list.Sort(_comparer); for (var i = 0; i < _list.Count - _maxCount; i++) { if (!WeaponUtil.IsC4p(_list[i].weaponObject.ConfigId)) //不回收C4 { _list[i].isFlagDestroy = true; } } } _lastTime = _contexts.session.commonSession.FreeArgs.Rule.ServerTime; }
private static string putOnPart(FreeData fd, int weaponType, FreeItemInfo info, string toInv = "", ServerRoom room = null) { WeaponResConfigItem weapon = GetWeapon(fd, weaponType); if (weapon != null) { foreach (EWeaponPartType part in SingletonManager.Get <WeaponPartsConfigManager>().GetAvaliablePartTypes(weapon.Id)) { int p = FreeWeaponUtil.GetWeaponPart(part); int detailId = WeaponUtil.GetRealAttachmentId(info.id, weapon.Id); if (SingletonManager.Get <WeaponPartsConfigManager>().IsPartMatchWeapon(detailId, weapon.Id)) { if ("p" + p == info.subType) { string inv = "w" + weaponType + p; ItemInventory ii = fd.freeInventory.GetInventoryManager().GetInventory(inv); if (ii != null && (ii.posList.Count == 0 || toInv.StartsWith("w" + weaponType))) { if (ii.posList.Count > 0) { DropPart(inv, fd, room); } return(inv); } } } } } return(null); }
private void DoHolsterStart(int?weaponId) { RelatedAppearence.JustUnMountWeaponFromHand(); if (weaponId.HasValue && WeaponUtil.IsC4p(weaponId.Value)) { UnArmC4(); } }
public void OnEnable() { weapon = WeaponUtil.CreateWeapon("GhWeaponShotgun"); weapon.shooter = this; weapon.target = GameObject.FindGameObjectWithTag("Player"); timer.Start(explosionTime); }
public void UnArmHeldWeapon(Action onfinish) { WeaponScanStruct weaponInfo = HeldWeaponAgent.ComponentScan; AppearanceSpecific(); float holsterParam = WeaponUtil.GetHolsterParam(HeldSlotType); RelatedStateInterface.CharacterUnmount(() => OnUnArmWeaponCallback(weaponInfo.ConfigId, onfinish), holsterParam); }
//有动作版移除 private void DoDrawUnarmWeaponWithAction() { DoSpecialAppearance(); int heldConfigId = HeldConfigId; float holsterParam = WeaponUtil.GetUnArmHolsterParam(HeldSlotType); RelatedCharState.CharacterUnmount(() => DoHolsterStart(heldConfigId), () => DoHolsterEnd(), holsterParam); onWeaponSwitchEvt(this, heldConfigId, EInOrOff.Off); }
internal EWeaponSlotType GetMatchedSlotType(int configId) { WeaponResConfigItem itemConfig; if (!WeaponUtil.VertifyWeaponConfigId(configId, out itemConfig)) { return(EWeaponSlotType.None); } return(GetMatchedSlotType((EWeaponType_Config)itemConfig.Type)); }
public bool IsWeaponInSlot(int configId) { EWeaponSlotType slotType = WeaponUtil.GetEWeaponSlotTypeById(configId); if (slotType == EWeaponSlotType.None) { return(false); } return(this[slotType].ConfigId == configId); }
public void SwitchBag(int index) { if (SwitchBagByReservedType(index)) { return; } var tarBag = FindWeaponBagDataBySlot(index); if (tarBag == null) { return; } var removedSlotList = new Byte[(int)EWeaponSlotType.Length]; DestroyWeapon(EWeaponSlotType.ThrowingWeapon, 0); RefreshWeaponAppearance(EWeaponSlotType.ThrowingWeapon); GrenadeHandler.ClearCache(); foreach (var weapon in tarBag.weaponList) { var slot = PlayerWeaponBagData.Index2Slot(weapon.Index); var weaponAllConfig = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(weapon.WeaponTplId); if (slot != EWeaponSlotType.ThrowingWeapon && slot != EWeaponSlotType.TacticWeapon) { var orient = WeaponUtil.CreateScan(weapon); orient.Bullet = weaponAllConfig.PropertyCfg.Bullet; orient.ReservedBullet = weaponAllConfig.PropertyCfg.Bulletmax; if (orient.Magazine > 0) { orient.Bullet += SingletonManager.Get <WeaponPartsConfigManager>().GetConfigById(orient.Magazine).Bullet; } ReplaceWeaponToSlot(slot, 0, orient); } else if (slot == EWeaponSlotType.ThrowingWeapon) { GrenadeHandler.AddCache(weapon.WeaponTplId); } removedSlotList[(int)slot] = 1; } removedSlotList[(int)EWeaponSlotType.TacticWeapon] = 1; removedSlotList[(int)EWeaponSlotType.ThrowingWeapon] = 1; for (int i = 1; i < removedSlotList.Length; i++) { if (removedSlotList[i] == 0) { DestroyWeapon((EWeaponSlotType)i, 0); } } EWeaponSlotType newSlot = PollGetLastSlotType(); TryHoldGrenade(true, false); TryArmWeaponImmediately(newSlot); }
public override void DoAction(IEventArgs args) { FreeRuleEventArgs fr = (FreeRuleEventArgs)args; IGameUnit unit = GetPlayer(args); if (unit != null) { PlayerEntity p = ((FreeData)unit).Player; int itemId = FreeUtil.ReplaceInt(weaponId, args); int index = FreeUtil.ReplaceInt(weaponKey, args); EWeaponSlotType st = FreeWeaponUtil.GetSlotType(index); WeaponBaseAgent agent = null; if (index == 0) { agent = p.WeaponController().HeldWeaponAgent; } else { agent = p.WeaponController().GetWeaponAgent(st); } if (agent != null && agent.IsValid() && !FreeUtil.ReplaceBool(replace, args)) { return; } var scan = WeaponUtil.CreateScan(itemId); if (FreeUtil.ReplaceBool(fullAmmo, args)) { var weaponAllConfig = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(itemId); scan.Bullet = weaponAllConfig.PropertyCfg.Bullet; scan.ReservedBullet = weaponAllConfig.PropertyCfg.Bulletmax; } if (index == 0) { p.WeaponController().PickUpWeapon(scan); } else { p.WeaponController().ReplaceWeaponToSlot(st, scan); if (p.stateInterface.State.CanDraw() && p.WeaponController().HeldSlotType == EWeaponSlotType.None) { p.WeaponController().TryArmWeaponImmediately(st); } } SimpleProto message = new SimpleProto(); message.Key = FreeMessageConstant.PlaySound; message.Ks.Add(2); message.Ins.Add((int)EAudioUniqueId.PickupWeapon); message.Bs.Add(true); FreeMessageSender.SendMessage(p, message); } }
private void GenerateBagWeaponByIndex(PlayerWeaponBagData srcBagData, IPlayerWeaponProcessor controller, List <int> reservedSubType) { var removedList = new List <EWeaponSlotType>(); for (EWeaponSlotType j = EWeaponSlotType.None + 1; j < EWeaponSlotType.Length; j++) { removedList.Add(j); } controller.GrenadeHandler.ClearCache(); foreach (PlayerWeaponData weapon in srcBagData.weaponList) { Logger.InfoFormat("[[[[[ServerInitialize data]]]]] BagIndex:{0}|In:{1}", srcBagData.BagIndex, weapon.ToString()); var weaponAllConfig = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(weapon.WeaponTplId); bool needReserved = true; if (null != reservedSubType && reservedSubType.Count != 0) { if (weaponAllConfig.NewWeaponCfg.Type == (int)EWeaponType_Config.ThrowWeapon) { needReserved = reservedSubType.Contains((int)EWeaponSubType.Throw); } else { needReserved = reservedSubType.Contains(weaponAllConfig.NewWeaponCfg.SubType); } } if (!needReserved) { continue; } var slot = PlayerWeaponBagData.Index2Slot(weapon.Index); var weaponType = (EWeaponType_Config)weaponAllConfig.NewWeaponCfg.Type; if (weaponType != EWeaponType_Config.ThrowWeapon) { var orient = WeaponUtil.CreateScan(weapon); orient.Bullet = weaponAllConfig.PropertyCfg.Bullet; orient.ReservedBullet = weaponAllConfig.PropertyCfg.Bulletmax; if (orient.Magazine > 0) { orient.Bullet += SingletonManager.Get <WeaponPartsConfigManager>().GetConfigById(orient.Magazine).Bullet; } controller.ReplaceWeaponToSlot(slot, srcBagData.BagIndex, orient); } else { controller.GrenadeHandler.AddCache(weapon.WeaponTplId); } removedList.Remove(slot); } foreach (var i in removedList) { controller.DestroyWeapon(i, 0); } }
public override void DoAction(IEventArgs args) { FreeRuleEventArgs fr = (FreeRuleEventArgs)args; IGameUnit unit = GetPlayer(args); if (unit != null) { PlayerEntity p = ((FreeData)unit).Player; int itemId = FreeUtil.ReplaceInt(weaponId, args); int index = FreeUtil.ReplaceInt(weaponKey, args); EWeaponSlotType st = FreeWeaponUtil.GetSlotType(index); Debug.LogFormat("add weapon: " + itemId + "," + index); Logger.Debug("add weapon to team " + p.playerInfo.Camp + " player " + p.playerInfo.PlayerName); SimpleProto message = new SimpleProto(); if (index == 0) { p.WeaponController().PickUpWeapon(WeaponUtil.CreateScan(itemId)); //p.bag.Bag.SetWeaponBullet(30); //p.bag.Bag.SetReservedCount(100); } else { p.WeaponController().ReplaceWeaponToSlot(st, WeaponUtil.CreateScan(itemId)); if (p.stateInterface.State.CanDraw() && p.WeaponController().HeldSlotType == EWeaponSlotType.None) { p.WeaponController().TryArmWeapon(st); } //SwitchWeaponAction.WeaponToHand(p, st); } message.Ins.Add(itemId); if (index > 0) { message.Ins.Add((int)st); } else { message.Ins.Add(-1); } message.Ks.Add(2); message.Key = FreeMessageConstant.ChangeAvatar; FreeMessageSender.SendMessage(p, message); //p.network.NetworkChannel.SendReliable((int)EServer2ClientMessage.FreeData, message); } }
//有动作版移除 private void DoDrawUnarmWeaponWithAction(Action callback) { DoSpecialAppearance(); int heldConfigId = HeldConfigId; float holsterParam = WeaponUtil.GetUnArmHolsterParam(HeldSlotType); RelatedCharState.CharacterUnmount(() => RelatedAppearence.JustUnMountWeaponFromHand(), () => DoUnArmFinished(heldConfigId, callback), holsterParam); onWeaponSwitchEvt(this, heldConfigId, EInOrOff.Off); }
private void OnUnArmWeaponCallback(int weaponId, Action onfinish) { RelatedAppearence.UnmountWeaponFromHand(); SetHeldSlotTypeProcess(EWeaponSlotType.None); if (WeaponUtil.IsC4p(weaponId)) { weaponInteract.UnmountC4(); } if (onfinish != null) { onfinish(); } }
public bool IsWeaponInSlot(int configId, int bagIndex = -1) { EWeaponSlotType slotType = WeaponUtil.GetEWeaponSlotTypeById(configId); if (slotType == EWeaponSlotType.None) { return(false); } if (bagIndex < 0) { bagIndex = HeldBagPointer; } return(CreateGetWeaponAgent(bagIndex, slotType).ConfigId == configId); }
//temporarily returning weapon list. Need to fix when implementing other drop types public WeaponDefinition[] generateLoot(string enemyId) { //check the enemy id matches a key in the enemy definitions if (!enemyDefinitions.definitions.ContainsKey(enemyId)) { throw new System.Exception("Missing enemy id."); } //retrieve the enemy details EnemyDefinition definition = enemyDefinitions.definitions[enemyId]; //create an array to store the loot drops WeaponDefinition[] generatedDefinitions = new WeaponDefinition[definition.lootDrops]; for (int i = 0; i < definition.lootDrops; i++) { //randomly select the loot drop type such as weapon, armour, resource etc. string dropType = ((WeightedString)WeightedValueSelector.selectValue(definition.lootDropTypes)).value; switch (dropType) { case "WEAPON": //using the selected loot drop type, randomly select the inner group of loot items such as assault_rifles WeaponLootDefinition weaponLootDefinition = ((WeaponLootDefinition)WeightedValueSelector.selectValue(definition.weaponWeights)); //randomly select the rarity type of the loot drop RarityObject.Rarity rarity = ((WeightedRarityObject)WeightedValueSelector.selectValue(weaponLootDefinition.rarityWeights)).value; //using the randomly selected information retrieve a weapon definition and add to loot list generatedDefinitions[i] = WeaponUtil.getWeapon(weaponLootDefinition.name, rarity); break; case "ARMOUR": break; case "INTEL": break; case "RESOURCE": break; case "NONE": break; } } //return the list of awarded loot types return(generatedDefinitions); }
public void SetBagHeldSlotType(EWeaponSlotType nowSlot) { var slot = (int)nowSlot; var bag = RelatedBagSet[0]; if (bag.HeldSlotPointer == slot) { return; } if (!WeaponUtil.VertifyEweaponSlotIndex(slot, true)) { return; } bag.ChangeSlotPointer(slot); }
private void OnUnArmWeaponCallback(int weaponId, Action onfinish) { RelatedAppearence.UnmountWeaponFromHand(); SetHeldSlotType(EWeaponSlotType.None); logger.InfoFormat("Do Weaopon HolsterEnd OnUnArmWeaponCallback {0}", HeldSlotType); if (WeaponUtil.IsC4p(weaponId)) { UnArmC4(); } if (onfinish != null) { onfinish(); } }
//直接放回装备 private void DoDrawUnarmWeaponWithoutAction(int?weaponId, Action callback) { RelatedAppearence.UnmountWeaponFromHand(); SetHeldSlotType(EWeaponSlotType.None); if (weaponId.HasValue && WeaponUtil.IsC4p(weaponId.Value)) { UnArmC4(); } ThrowActionExecute(); if (callback != null) { callback(); } }
private void DoUnArmFinished(int?weaponId, Action callback) { RelatedAppearence.JustClearOverrideController(); SetHeldSlotType(EWeaponSlotType.None); if (weaponId.HasValue && WeaponUtil.IsC4p(weaponId.Value)) { UnArmC4(); } ThrowActionExecute(); if (callback != null) { callback(); } }
public void SetBagHeldSlotType(EWeaponSlotType nowSlot) { var slot = (byte)nowSlot; var relatedCustomize = RelatedCustomize; if (relatedCustomize.HeldSlotPointer == slot) { return; } if (!WeaponUtil.VertifyEweaponSlotIndex(slot, true)) { return; } relatedCustomize.ChangeSlotPointer(slot); }
public WeaponDrawAppearanceStruct GetDrawAppearanceStruct(EWeaponSlotType slot) { var weaponDrawStruct = new WeaponDrawAppearanceStruct(); var armOnLeft = FilterHoldSecondWeapon(); var drawOnLeft = armOnLeft && (slot != EWeaponSlotType.PistolWeapon && slot != EWeaponSlotType.MeleeWeapon && slot != EWeaponSlotType.ThrowingWeapon); weaponDrawStruct.holsterParam = WeaponUtil.GetHolsterParam(armOnLeft); weaponDrawStruct.targetSlot = slot; weaponDrawStruct.drawParam = drawOnLeft ? AnimatorParametersHash.Instance.DrawLeftValue : AnimatorParametersHash.Instance.DrawRightValue; weaponDrawStruct.armOnLeft = armOnLeft; return(weaponDrawStruct); }