private void HandleBullet(IEventArgs args) { if ("SetWeaponClip" == code) { FreeData fd = (FreeData)((FreeRuleEventArgs)args).GetUnit("current"); int ClipType = FreeUtil.ReplaceInt("{item.ClipType}", args); fd.Player.WeaponController().SetReservedBullet((EBulletCaliber)ClipType, CarryClipUtil.GetClipCount(ClipType, fd, args)); } else if ("ClearWeaponClip" == code) { FreeData fd = (FreeData)((FreeRuleEventArgs)args).GetUnit("current"); int ClipType = FreeUtil.ReplaceInt("{item.ClipType}", args); if (fd != null) { fd.Player.WeaponController().SetReservedBullet((EBulletCaliber)ClipType, 0); } } else if ("SetItemClip" == code) { FreeData fd = (FreeData)((FreeRuleEventArgs)args).GetUnit("current"); int ClipType = FreeUtil.ReplaceInt("{state.ClipType}", args); int count = fd.Player.WeaponController().GetReservedBullet((EBulletCaliber)ClipType); int itemCount = CarryClipUtil.GetClipCount(ClipType, fd, args); int delta = count - itemCount; if (delta > 0) { CarryClipUtil.AddClip(Math.Abs(delta), ClipType, fd, args); } else { CarryClipUtil.DeleteClip(Math.Abs(delta), ClipType, fd, args); } } }
private void HandleDropWeapon(IEventArgs args) { if ("DropWeapon" == code) { int key = FreeUtil.ReplaceInt("{key}", args); FreeData fd = (FreeData)args.GetUnit("current"); ItemInventory defInv = fd.freeInventory.GetInventoryManager().GetDefaultInventory(); for (int i = 1; i <= 5; i++) { ItemInventory ii = fd.freeInventory.GetInventoryManager().GetInventory("w" + key + "" + i); if (ii.posList.Count > 0) { ItemPosition ip = ii.posList[0]; if (BagCapacityUtil.CanAddToBag(args, fd, ip)) { int[] next = defInv.GetNextEmptyPosition(ip.key); ItemInventoryUtil.MovePosition(ip, defInv, next[0], next[1], (ISkillArgs)args); } else { ItemInventory ground = fd.freeInventory.GetInventoryManager().GetInventory("ground"); int[] next = ground.GetNextEmptyPosition(ip.key); ItemInventoryUtil.MovePosition(ip, ground, next[0], next[1], (ISkillArgs)args); } } } CarryClipUtil.AddCurrentClipToBag(key, fd, args); } }
public void Handle(ServerRoom room, PlayerEntity player, SimpleProto message) { FreeData fd = (FreeData)player.freeData.FreeData; room.ContextsWrapper.FreeArgs.TempUse(PARA_PLAYER_CURRENT, fd); string key = message.Ss[0]; int count = message.Ins[0]; if (key.StartsWith(ChickenConstant.BagDefault)) { ItemPosition ip = FreeItemManager.GetItemPosition(room.ContextsWrapper.FreeArgs, key, fd.GetFreeInventory().GetInventoryManager()); FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey()); if (ip.GetCount() > count) { if (info.cat == (int)ECategory.Weapon && SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(info.id).Type == (int)EWeaponType_Config.ThrowWeapon) { CarryClipUtil.DeleteGrenade(count, info.id, fd, room.ContextsWrapper.FreeArgs); for (int i = 0; i < count; i++) { player.WeaponController().RemoveGreande(info.id); } } else { ip.SetCount(ip.GetCount() - count); ip.GetInventory().GetInventoryUI().ReDraw((ISkillArgs)room.ContextsWrapper.FreeArgs, ip.GetInventory(), true); } } else { ip.GetInventory().RemoveItem((ISkillArgs)room.ContextsWrapper.FreeArgs, ip); } room.RoomContexts.session.entityFactoryObject.SceneObjectEntityFactory.CreateSimpleObjectEntity( (ECategory)info.cat, info.id, count, fd.Player.position.Value); if (info.cat == (int)ECategory.GameItem && SingletonManager.Get <GameItemConfigManager>().GetConfigById(info.id).Type == (int)GameItemType.Bullet) { player.WeaponController().SetReservedBullet((EBulletCaliber)info.id, CarryClipUtil.GetClipCount(info.id, fd, room.ContextsWrapper.FreeArgs)); } SimpleProto sp = FreePool.Allocate(); sp.Key = FreeMessageConstant.PlaySound; sp.Ks.Add(2); sp.Ins.Add(5017); sp.Bs.Add(false); FreeMessageSender.SendMessage(fd.Player, sp); } room.ContextsWrapper.FreeArgs.Resume(PARA_PLAYER_CURRENT); }
/// <summary> /// 增加背包中的子弹的时候,更新武器的备弹数 /// </summary> /// <param name="args"></param> /// <param name="clipType">子弹类型</param> private void HandleSetClip(IEventArgs args, int clipType) { FreeData fd = (FreeData)((FreeRuleEventArgs)args).GetUnit(FreeArgConstant.PlayerCurrent); fd.Player.WeaponController().SetReservedBullet((EBulletCaliber)clipType, CarryClipUtil.GetClipCount(clipType, fd, args)); }
/// <summary> /// 处理武器相关的特殊逻辑 /// </summary> /// <param name="args"></param> public override void DoAction(IEventArgs args) { IParable para = args.GetUnit("state"); var contexts = args.GameContext; var playerEntity = (PlayerEntity)((SimpleParable)para).GetFieldObject(0); if (para != null) { var controller = playerEntity.WeaponController(); //TODO 确认逻辑 var lastId = controller.GetWeaponAgent(EWeaponSlotType.LastPointer).ConfigId; var currentId = controller.HeldWeaponAgent.ConfigId; //if(null != weaponData) //{ // currentId = weaponData.WeaponId; //} //if(null != lastWeaponData) //{ // lastId = lastWeaponData.WeaponId; //} FreeData fd = (FreeData)((FreeRuleEventArgs)args).GetUnit(FreeArgConstant.PlayerCurrent); if (currentId > 0) { WeaponResConfigItem item = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(currentId); if (item.Type == (int)EWeaponType_Config.ThrowWeapon) { CarryClipUtil.DeleteGrenade(1, lastId, fd, args); if (lastId != currentId) { ItemInventory grenade = fd.freeInventory.GetInventoryManager().GetInventory(ChickenConstant.BagGrenadeWeapon); } } else { int ClipType = FreeUtil.ReplaceInt("{state.ClipType}", args); int count = fd.Player.WeaponController().GetReservedBullet((EBulletCaliber)ClipType); int itemCount = CarryClipUtil.GetClipCount(ClipType, fd, args); int delta = count - itemCount; if (delta > 0) { CarryClipUtil.AddClip(Math.Abs(delta), ClipType, fd, args); } else { CarryClipUtil.DeleteClip(Math.Abs(delta), ClipType, fd, args); } } } else { if (lastId != 0) { CarryClipUtil.DeleteGrenade(1, lastId, fd, args); ItemInventory grenade = fd.freeInventory.GetInventoryManager().GetInventory(ChickenConstant.BagGrenadeWeapon); grenade.RemoveItem((ISkillArgs)args, grenade.posList[0]); } } } }