public static bool CanChangeBag(IEventArgs args, FreeData fd, int cat, int id) { bool can = true; float capacity = GetCapacity(fd); float weight = GetWeight(fd); FreeItemInfo info = FreeItemConfig.GetItemInfo(cat, id); if (cat == (int)ECategory.Avatar) { float oldCap = GetCapacity(fd, cat, id); can = Math.Round(capacity - weight, 3) >= Math.Round(oldCap - info.capacity, 3); } if (!can) { UseCommonAction use = new UseCommonAction(); use.key = "showBottomTip"; use.values = new List <ArgValue>(); use.values.Add(new ArgValue("msg", "{desc:10074}")); args.TempUse("current", fd); use.Act(args); args.Resume("current"); } return(can); }
// 获取给定物品在玩家身上相同类型的物品的容量 public static float GetCapacity(FreeData fd, int cat, int id) { foreach (string name in fd.freeInventory.GetInventoryManager().GetInventoryNames()) { if (name != ChickenConstant.BagGround) { ItemInventory ii = fd.freeInventory.GetInventoryManager().GetInventory(name); if (ii != null) { foreach (ItemPosition ip in ii.GetItems()) { FreeItemInfo currentInfo = FreeItemConfig.GetItemInfo(ip.GetKey().GetKey()); if (currentInfo.cat == (int)ECategory.Avatar && cat == (int)ECategory.Avatar) { RoleAvatarConfigItem avatar1 = SingletonManager.Get <RoleAvatarConfigManager>().GetConfigById(currentInfo.id); RoleAvatarConfigItem avatar2 = SingletonManager.Get <RoleAvatarConfigManager>().GetConfigById(id); if (avatar1.Type == avatar2.Type) { return(avatar1.Capacity); } } } } } } return(0); }
public void Handle(ServerRoom room, PlayerEntity player, SimpleProto message) { FreeData fd = (FreeData)player.freeData.FreeData; room.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.FreeArgs, key, fd.GetFreeInventory().GetInventoryManager()); FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey()); if (ip.GetCount() > count) { ip.SetCount(ip.GetCount() - count); ip.GetInventory().GetInventoryUI().ReDraw((ISkillArgs)room.FreeArgs, ip.GetInventory(), true); } else { ip.GetInventory().RemoveItem((ISkillArgs)room.FreeArgs, ip); } room.RoomContexts.session.entityFactoryObject.SceneObjectEntityFactory.CreateSimpleEquipmentEntity( (Assets.XmlConfig.ECategory)info.cat, info.id, count, fd.Player.position.Value); } room.FreeArgs.Resume(PARA_PLAYER_CURRENT); }
// 获取玩家总容量 public static float GetCapacity(FreeData fd) { float w = 20; foreach (string name in fd.freeInventory.GetInventoryManager().GetInventoryNames()) { if (name != "ground") { ItemInventory ii = fd.freeInventory.GetInventoryManager().GetInventory(name); if (ii != null) { foreach (ItemPosition ip in ii.GetItems()) { FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.GetKey().GetKey()); if (info.cat == 9) { RoleAvatarConfigItem avatar = SingletonManager.Get <RoleAvatarConfigManager>().GetConfigById(info.id); w += avatar.Capacity; } } } } } return(w); }
public void ReDraw(ISkillArgs args, ItemInventory inventory, bool includeBack) { SimpleProto sp = FreePool.Allocate(); sp.Key = FreeMessageConstant.InventoyUI; // 0 重绘,1 添加,2 删除, 3 更新 sp.Ks.Add(0); sp.Bs.Add(true); sp.Ks.Add(inventory.posList.Count); foreach (ItemPosition ip in inventory.posList) { FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.GetKey().GetKey()); sp.Ins.Add(info.cat); sp.Ins.Add(info.id); sp.Ins.Add(ip.GetCount()); sp.Ss.Add(inventory.GetName() + "," + ip.GetX() + "," + ip.GetY()); } FreeData fd = (FreeData)args.GetUnit("current"); sp.Ks.Add((int)BagCapacityUtil.GetCapacity(fd)); sp.Ks.Add((int)Math.Ceiling(BagCapacityUtil.GetWeight(fd))); SendMessageAction.sender.SendMessage(args, sp, 1, "current"); ChickenFuncUtil.UpdateBagCapacity(args, (int)Math.Ceiling(BagCapacityUtil.GetWeight(fd)), BagCapacityUtil.GetCapacity(fd)); }
public static void DeleteClip(int count, int clipType, FreeData fd, IEventArgs args) { int leftCount = count; ItemPosition[] ips = fd.freeInventory.GetInventoryManager().GetDefaultInventory().GetItems(); List <ItemPosition> remove = new List <ItemPosition>(); foreach (ItemPosition ip in ips) { FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey()); if (ip.GetParameters().HasPara("ClipType") && (int)ip.GetParameters().Get("ClipType").GetValue() == clipType) { if (leftCount >= ip.GetCount()) { leftCount -= ip.GetCount(); remove.Add(ip); if (leftCount == 0) { break; } } else { ip.SetCount(ip.GetCount() - leftCount); ip.GetInventory().GetInventoryUI().UpdateItem((FreeRuleEventArgs)args, ip.GetInventory(), ip); break; } } } foreach (ItemPosition ip in remove) { fd.freeInventory.GetInventoryManager().GetDefaultInventory().RemoveItem((FreeRuleEventArgs)args, ip); } }
private static void DropPart(string inv, FreeData fd, ServerRoom room) { int c3 = fd.freeInventory.GetInventoryManager().GetInventory(inv).posList.Count; ItemInventory w3 = fd.freeInventory.GetInventoryManager().GetInventory(inv); if (c3 > 0) { ItemPosition ip = w3.posList[0]; w3.RemoveItem(room.FreeArgs, ip); FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.GetKey().GetKey()); if (BagCapacityUtil.CanAddToBag(room.FreeArgs, fd, ip)) { fd.freeInventory.GetInventoryManager().GetDefaultInventory().AddItem(room.FreeArgs, ip.key, true); } else { if (info.cat > 0) { room.RoomContexts.session.entityFactoryObject.SceneObjectEntityFactory.CreateSimpleEquipmentEntity( (ECategory)info.cat, info.id, ip.GetCount(), fd.Player.position.Value); } } } }
public static float HandleDamage(IEventArgs args, FreeData fd, PlayerDamageInfo damage) { float readDamage = damage.damage; if (damage.type != (int)EUIDeadType.Weapon && damage.type != (int)EUIDeadType.Unarmed) { return(readDamage); } if (damage.part == (int)EBodyPart.Head) { ItemPosition ip = GetHelmet(fd); if (ip != null) { FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey()); int percent = 0; if (info.id == 8) { percent = 30; } if (info.id == 9) { percent = 40; } else if (info.id == 10) { percent = 55; } readDamage = ReduceDamage(args, fd, damage, ip, percent, ItemType.Helmet); } } else if (damage.part == (int)EBodyPart.Chest || damage.part == (int)EBodyPart.Stomach || damage.part == (int)EBodyPart.Pelvis) { ItemPosition ip = GetArmor(fd); if (ip != null) { FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey()); int percent = 0; if (info.id == 1) { percent = 30; } if (info.id == 2) { percent = 40; } else if (info.id == 3) { percent = 55; } readDamage = ReduceDamage(args, fd, damage, ip, percent, ItemType.Armor); } } return(readDamage); }
public static void UpdateGamePlayData(FreeData fd, ItemPosition ip, ItemType itemType) { GamePlayComponent gamePlay = fd.Player.gamePlay; if (ip == null) { if (itemType == ItemType.Armor) { gamePlay.MaxArmor = 0; gamePlay.CurArmor = 0; } if (itemType == ItemType.Helmet) { gamePlay.MaxHelmet = 0; gamePlay.CurHelmet = 0; } } else { FreeItemInfo itemInfo = FreeItemConfig.GetItemInfo(ip.key.GetKey()); switch (itemType) { case ItemType.Armor: gamePlay.CurArmor = Math.Max(0, ip.GetCount()); if (itemInfo.id == 1) { gamePlay.MaxArmor = 200; } else if (itemInfo.id == 2) { gamePlay.MaxArmor = 220; } else if (itemInfo.id == 3) { gamePlay.MaxArmor = 250; } break; case ItemType.Helmet: gamePlay.CurHelmet = Math.Max(0, ip.GetCount()); if (itemInfo.id == 8) { gamePlay.MaxHelmet = 80; } else if (itemInfo.id == 9) { gamePlay.MaxHelmet = 150; } else if (itemInfo.id == 10) { gamePlay.MaxHelmet = 230; } break; } } }
private static float ReduceDamage(IEventArgs args, PlayerEntity player, PlayerDamageInfo damage, int percent, bool armor) { float readDamage = damage.damage; if (damage.type != (int)EUIDeadType.Weapon && damage.type != (int)EUIDeadType.Unarmed) { return(readDamage); } float reduce = damage.damage * percent / 100; float realReduce = reduce; if (armor) { realReduce = Math.Min(player.gamePlay.CurArmor, reduce); } else { realReduce = Math.Min(player.gamePlay.CurHelmet, reduce); } damage.damage -= realReduce; FreeData fd = (FreeData)player.freeData.FreeData; // 普通帽子不减少 args.TempUse("current", fd); if (realReduce > 0) { if (armor) { player.gamePlay.CurArmor = Math.Max(0, player.gamePlay.CurArmor - (int)readDamage); if (player.gamePlay.CurArmor == 0) { PlayerItemAvatarAction.TakeOff(player, player.gamePlay.ArmorLv); FreeItemInfo info = FreeItemConfig.GetItemInfo((int)ECategory.Avatar, player.gamePlay.ArmorLv); FuntionUtil.Call(args, "showBottomTip", "msg", "{desc:10075," + info.name + "}"); } } else { player.gamePlay.CurHelmet = Math.Max(0, player.gamePlay.CurHelmet - (int)readDamage); if (player.gamePlay.CurHelmet == 0) { PlayerItemAvatarAction.TakeOff(player, player.gamePlay.HelmetLv); FreeItemInfo info = FreeItemConfig.GetItemInfo((int)ECategory.Avatar, player.gamePlay.HelmetLv); FuntionUtil.Call(args, "showBottomTip", "msg", "{desc:10075," + info.name + "}"); } } player.statisticsData.Statistics.DefenseDamage += realReduce; } args.Resume("current"); return(damage.damage); }
public static void UpdateArmorAndHelmet(FreeData fd) { UpdateGamePlayData(fd, GetArmor(fd), ItemType.Armor); UpdateGamePlayData(fd, GetHelmet(fd), ItemType.Helmet); if (FreeItemConfig.GetItemInfo(GetArmor(fd).key.GetKey()).id == 3 && FreeItemConfig.GetItemInfo(GetHelmet(fd).key.GetKey()).id == 10 && FreeItemConfig.GetItemInfo(GetBag(fd).key.GetKey()).id == 6) { fd.Player.statisticsData.Statistics.IsFullArmed = true; } }
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); }
public static void UpdateArmorAndHelmet(FreeData fd) { UpdateGamePlayData(fd, GetArmor(fd), ItemType.Armor); UpdateGamePlayData(fd, GetHelmet(fd), ItemType.Helmet); var armor = GetArmor(fd); var helmet = GetHelmet(fd); var bag = GetBag(fd); if (null != armor && FreeItemConfig.GetItemInfo(armor.key.GetKey()).id == 3 && null != helmet && FreeItemConfig.GetItemInfo(helmet.key.GetKey()).id == 10 && null != bag && FreeItemConfig.GetItemInfo(bag.key.GetKey()).id == 6) { fd.Player.statisticsData.Statistics.IsFullArmed = true; } }
// 获取玩家物品总重量 public static float GetWeight(FreeData fd) { float w = 0; ItemInventory ii = fd.GetFreeInventory().GetInventoryManager().GetDefaultInventory(); if (ii != null) { foreach (ItemPosition ip in ii.GetItems()) { FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.GetKey().GetKey()); w += ip.GetCount() * info.weight; } } return(w); }
public static bool CanTakeOff(IEventArgs args, FreeData fd, int cat, int id) { FreeItemInfo info = FreeItemConfig.GetItemInfo(cat, id); if (info.cat == (int)ECategory.Avatar) { if (GetCapacity(fd) - GetWeight(fd) < info.capacity) { SimpleProto msg = FreePool.Allocate(); msg.Key = FreeMessageConstant.ChickenTip; msg.Ss.Add("word74"); FreeMessageSender.SendMessage(fd.Player, msg); return(false); } } return(true); }
private bool HandleBag(string from, string to, ServerRoom room, FreeData fd) { FreeItemInfo info = null; if (from.StartsWith(ChickenConstant.BagGround)) { SimpleItemInfo sinfo = PickupItemUtil.GetGroundItemInfo(room, fd, from); info = FreeItemConfig.GetItemInfo(sinfo.cat, sinfo.id); } else { ItemPosition ip = FreeItemManager.GetItemPosition(room.ContextsWrapper.FreeArgs, from, fd.freeInventory.GetInventoryManager()); if (ip == null) { ItemInventory ii = fd.freeInventory.GetInventoryManager().GetInventory(from.Trim()); if (ii != null && ii.posList.Count > 0) { ip = ii.posList[0]; } } if (ip != null) { info = FreeItemConfig.GetItemInfo(ip.key.GetKey()); } } if (info != null && info.cat == 9) { RoleAvatarConfigItem avatar = SingletonManager.Get <RoleAvatarConfigManager>().GetConfigById(info.id); if (avatar.Capacity > 0) { if (from.StartsWith(ChickenConstant.BagGround) && !to.StartsWith(ChickenConstant.BagGround)) { return(BagCapacityUtil.CanAddToBag(room.ContextsWrapper.FreeArgs, fd, info.cat, info.id, 1)); } if (to.StartsWith(ChickenConstant.BagGround) && !from.StartsWith(ChickenConstant.BagGround)) { return(BagCapacityUtil.CanTakeOff(room.ContextsWrapper.FreeArgs, fd, info.cat, info.id)); } } } return(true); }
public void Handle(ServerRoom room, PlayerEntity player, SimpleProto message) { if (BagCapacityUtil.CanAddToBagCount(room.ContextsWrapper.FreeArgs, (FreeData)player.freeData.FreeData, message.Ins[1], message.Ins[2], message.Ins[3]) > 0) { if (PickupItemUtil.AddItemToPlayer(room, player, message.Ins[0], message.Ins[1], message.Ins[2], message.Ins[3])) { FreeItemInfo item = FreeItemConfig.GetItemInfo(message.Ins[1], message.Ins[2]); if (item.subType == "w4" || item.subType == "w6" || item.subType == "w7") { SimpleProto sp = FreePool.Allocate(); sp.Key = FreeMessageConstant.PlaySound; sp.Ks.Add(2); sp.Ins.Add((int)EAudioUniqueId.PickupWeapon); sp.Bs.Add(true); FreeMessageSender.SendMessage(player, sp); } } } }
public static int CanAddToBagCount(IEventArgs args, FreeData fd, int cat, int id, int count) { if (count > 1) { int canCount = 0; float capacity = GetCapacity(fd); float weight = GetWeight(fd); FreeItemInfo info = FreeItemConfig.GetItemInfo(cat, id); if (cat == (int)ECategory.GameItem || cat == (int)ECategory.WeaponPart) { canCount = (int)(Math.Round(capacity - weight, 3) / info.weight); } if (cat == (int)ECategory.Weapon) { WeaponResConfigItem item = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(id); if (item.Type == (int)EWeaponType_Config.ThrowWeapon) { canCount = (int)(Math.Round(capacity - weight, 3) / info.weight); } } int realCount = Math.Min(count, canCount); if (realCount == 0) { UseCommonAction use = new UseCommonAction(); use.key = "showBottomTip"; use.values = new List <ArgValue>(); use.values.Add(new ArgValue("msg", "{desc:10073}")); args.TempUse("current", fd); use.Act(args); args.Resume("current"); } return(realCount); } return(CanAddToBag(args, fd, cat, id, count) ? 1 : 0); }
private int CreateItemFromInventory(IEventArgs fr, FreeData fd, ItemInventory ii, Vector3 p, string realName, int entityId) { int itemAdded = 0; if (ii != null && ii.name != ChickenConstant.BagGround) { foreach (ItemPosition ip in ii.GetItems()) { FreeMoveEntity en = fr.GameContext.freeMove.CreateEntity(); en.AddEntityKey(new EntityKey(fr.GameContext.session.commonSession.EntityIdGenerator.GetNextEntityId(), (short)EEntityType.FreeMove)); en.AddPosition(); en.position.Value = new Vector3(p.x, p.y, p.z); en.AddFreeData(FreeUtil.ReplaceVar(name, fr), null); en.AddPositionFilter(Core.Components.PositionFilterType.Filter2D, 1000); en.freeData.Cat = FreeEntityConstant.DeadBox; FreeItemInfo itemInfo = FreeItemConfig.GetItemInfo(ip.GetKey().GetKey()); if (itemInfo.cat == (int)ECategory.Weapon) { int key = CarryClipUtil.GetWeaponKey(ii.name, fd); if (key >= 1 && key <= 3) { CarryClipUtil.AddCurrentClipToBag(key, fd, fr); } } en.AddFlagImmutability(fr.GameContext.session.currentTimeObject.CurrentTime); SimpleItemInfo info = new SimpleItemInfo(realName, itemInfo.cat, itemInfo.id, ip.GetCount(), en.entityKey.Value.EntityId); en.freeData.Value = SingletonManager.Get <DeadBoxParser>().ToString(info); en.freeData.IntValue = entityId; en.isFlagSyncNonSelf = true; itemAdded++; } } return(itemAdded); }
public static bool CanAddToBag(IEventArgs args, FreeData fd, int cat, int id, int count) { bool can = true; float capacity = GetCapacity(fd); float weight = GetWeight(fd); FreeItemInfo info = FreeItemConfig.GetItemInfo(cat, id); if (cat == (int)ECategory.Avatar) { float oldCap = GetCapacity(fd, cat, id); can = Math.Round(capacity - weight, 3) >= oldCap - info.capacity; } if (cat == (int)ECategory.GameItem || cat == (int)ECategory.WeaponPart) { can = Math.Round(capacity - weight, 3) >= info.weight * count; } if (cat == (int)ECategory.Weapon) { WeaponResConfigItem item = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(id); if (item.Type == (int)EWeaponType_Config.ThrowWeapon) { can = Math.Round(capacity - weight, 3) >= info.weight * count; } } if (!can) { UseCommonAction use = new UseCommonAction(); use.key = "showBottomTip"; use.values = new List <ArgValue>(); use.values.Add(new ArgValue("msg", "{desc:10073}")); args.TempUse("current", fd); use.Act(args); args.Resume("current"); } return(can); }
private static void DropItem(string inv, FreeData fd, ServerRoom room) { Debug.LogFormat("inv {0}", inv); int c3 = fd.freeInventory.GetInventoryManager().GetInventory(inv).posList.Count; ItemInventory w3 = fd.freeInventory.GetInventoryManager().GetInventory(inv); if (c3 > 0) { ItemPosition ip = w3.posList[0]; w3.RemoveItem(room.ContextsWrapper.FreeArgs, ip); FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.GetKey().GetKey()); if (info.cat > 0) { /*room.RoomContexts.session.entityFactoryObject.SceneObjectEntityFactory.CreateSimpleObjectEntity((ECategory)info.cat, * info.id, ip.GetCount(), fd.Player.position.Value, ip.GetCount());*/ CreateSceneObjectAction.CreateDropItem(fd.Player, info.cat, info.id, ip.GetCount(), room.RoomContexts.session.entityFactoryObject.SceneObjectEntityFactory); } } }
public static void ShowSplitUI(ServerRoom room, FreeData fd, string key) { // 分拆道具 if (key.StartsWith("default")) { ItemPosition ip = FreeItemManager.GetItemPosition(room.FreeArgs, key, fd.GetFreeInventory().GetInventoryManager()); FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey()); if (ip.count > 1) { SimpleProto data = FreePool.Allocate(); data.Key = FreeMessageConstant.ShowSplitUI; data.Ins.Add(info.cat); data.Ins.Add(info.id); data.Ins.Add(ip.count); data.Ss.Add(key); data.Ss.Add(ip.GetKey().GetName()); FreeMessageSender.SendMessage(fd.Player, data); } } }
public static void ShowSplitUI(ServerRoom room, FreeData fd, string key) { // 分拆道具 if (key.StartsWith(ChickenConstant.BagDefault)) { ItemPosition ip = FreeItemManager.GetItemPosition(room.ContextsWrapper.FreeArgs, key, fd.GetFreeInventory().GetInventoryManager()); FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey()); var stackable = true; if (info.cat == (int)ECategory.Weapon) { WeaponResConfigItem item = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(info.id); if (item.Type != (int)EWeaponType_Config.ThrowWeapon) { stackable = false; } } else { if (info.stack <= 1) { stackable = false; } } SimpleProto data = FreePool.Allocate(); if (!stackable || ip.count <= 1) { data.Key = FreeMessageConstant.ChickenTip; data.Ss.Add("word78"); FreeMessageSender.SendMessage(fd.Player, data); return; } data.Key = FreeMessageConstant.ShowSplitUI; data.Ins.Add(info.cat); data.Ins.Add(info.id); data.Ins.Add(ip.count); data.Ss.Add(key); data.Ss.Add(ip.GetKey().GetName()); FreeMessageSender.SendMessage(fd.Player, data); PlayerStateUtil.AddPlayerState(EPlayerGameState.InterruptItem, fd.Player.gamePlay); } }
public static bool CanAddToBag(IEventArgs args, FreeData fd, int cat, int id, int count) { bool can = true; float capacity = GetCapacity(fd); float weight = GetWeight(fd); FreeItemInfo info = FreeItemConfig.GetItemInfo(cat, id); if (info == null) { return(false); // 无效道具 } if (cat == (int)ECategory.Avatar) { float oldCap = GetCapacity(fd, cat, id); can = Math.Round(capacity - weight, 3) >= oldCap - info.capacity; } if (cat == (int)ECategory.GameItem || cat == (int)ECategory.WeaponPart) { can = Math.Round(capacity - weight, 3) >= info.weight * count; } if (cat == (int)ECategory.Weapon) { WeaponResConfigItem item = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(id); if (item.Type == (int)EWeaponType_Config.ThrowWeapon) { can = Math.Round(capacity - weight, 3) >= info.weight * count; } } if (!can) { SimpleProto msg = FreePool.Allocate(); msg.Key = FreeMessageConstant.ChickenTip; msg.Ss.Add("word73"); FreeMessageSender.SendMessage(fd.Player, msg); } return(can); }
// 获取玩家总容量 public static float GetCapacity(FreeData fd) { float w = 70; /*foreach (string name in fd.freeInventory.GetInventoryManager().GetInventoryNames()) * { * if (name != ChickenConstant.BagGround) * { * ItemInventory ii = fd.freeInventory.GetInventoryManager().GetInventory(name); * if (ii != null) * { * foreach (ItemPosition ip in ii.GetItems()) * { * FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.GetKey().GetKey()); * if (info.cat == 9) * { * RoleAvatarConfigItem avatar = SingletonManager.Get<RoleAvatarConfigManager>().GetConfigById(info.id); * w += avatar.Capacity; * } * } * } * } * }*/ ItemInventory ii = fd.freeInventory.GetInventoryManager().GetInventory(ChickenConstant.BagBag); if (ii != null) { foreach (ItemPosition ip in ii.GetItems()) { FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.GetKey().GetKey()); if (info.cat == 9) { RoleAvatarConfigItem avatar = SingletonManager.Get <RoleAvatarConfigManager>().GetConfigById(info.id); w += avatar.Capacity; } } } return(w); }
public static int CanAddToBagCount(IEventArgs args, FreeData fd, int cat, int id, int count) { if (count > 1 && cat != (int)ECategory.Avatar) { int canCount = 0; float capacity = GetCapacity(fd); float weight = GetWeight(fd); FreeItemInfo info = FreeItemConfig.GetItemInfo(cat, id); if (cat == (int)ECategory.GameItem || cat == (int)ECategory.WeaponPart) { canCount = (int)(Math.Round(capacity - weight, 3) / info.weight); } if (cat == (int)ECategory.Weapon) { WeaponResConfigItem item = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(id); if (item.Type == (int)EWeaponType_Config.ThrowWeapon) { canCount = (int)(Math.Round(capacity - weight, 3) / info.weight); } if (item.Type == (int)EWeaponType_Config.Armor || item.Type == (int)EWeaponType_Config.Helmet) { canCount = count; } } int realCount = Math.Min(count, canCount); if (realCount == 0) { SimpleProto msg = FreePool.Allocate(); msg.Key = FreeMessageConstant.ChickenTip; msg.Ss.Add("word73"); FreeMessageSender.SendMessage(fd.Player, msg); } return(realCount); } return(CanAddToBag(args, fd, cat, id, count) ? 1 : 0); }
public static bool CanChangeBag(IEventArgs args, FreeData fd, int cat, int id) { bool can = true; float capacity = GetCapacity(fd); float weight = GetWeight(fd); FreeItemInfo info = FreeItemConfig.GetItemInfo(cat, id); if (cat == (int)ECategory.Avatar) { float oldCap = GetCapacity(fd, cat, id); can = Math.Round(capacity - weight, 3) >= Math.Round(oldCap - info.capacity, 3); } if (!can) { SimpleProto msg = FreePool.Allocate(); msg.Key = FreeMessageConstant.ChickenTip; msg.Ss.Add("word74"); FreeMessageSender.SendMessage(fd.Player, msg); } return(can); }
public void ReDraw(ISkillArgs args, ItemInventory inventory, bool includeBack) { SimpleProto itemInfo = FreePool.Allocate(); itemInfo.Key = FreeMessageConstant.ItemInfo; itemInfo.Ss.Add(inventory.name); if (inventory.posList.Count > 0) { ItemPosition ip = inventory.posList[0]; itemInfo.Bs.Add(false); FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey()); itemInfo.Ins.Add(info.cat); itemInfo.Ins.Add(info.id); itemInfo.Ins.Add(ip.GetCount()); } else { itemInfo.Bs.Add(true); } FreeMessageSender.SendMessage(args, "current", itemInfo); }
public static bool CanTakeOff(IEventArgs args, FreeData fd, int cat, int id) { FreeItemInfo info = FreeItemConfig.GetItemInfo(cat, id); if (info.cat == (int)ECategory.Avatar) { if (GetCapacity(fd) - GetWeight(fd) < info.capacity) { UseCommonAction use = new UseCommonAction(); use.key = "showBottomTip"; use.values = new List <ArgValue>(); use.values.Add(new ArgValue("msg", "{desc:10074}")); args.TempUse("current", fd); use.Act(args); args.Resume("current"); return(false); } } return(true); }
public static void AddClip(int count, int clipType, FreeData fd, IEventArgs args) { if (BagCapacityUtil.CanAddToBag(args, fd, (int)ECategory.GameItem, clipType, count)) { int leftCount = count; ItemPosition[] ips = fd.freeInventory.GetInventoryManager().GetDefaultInventory().GetItems(); foreach (ItemPosition ip in ips) { FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey()); if (ip.GetParameters().HasPara("ClipType") && (int)ip.GetParameters().Get("ClipType").GetValue() == clipType) { int added = Math.Min(leftCount, info.stack - ip.count); leftCount -= added; ip.SetCount(ip.GetCount() + added); ip.GetInventory().GetInventoryUI().UpdateItem((FreeRuleEventArgs)args, ip.GetInventory(), ip); } } if (leftCount > 0) { FreeItem item = FreeItemManager.GetItem((FreeRuleEventArgs)args, FreeItemConfig.GetItemKey((int)ECategory.GameItem, clipType), leftCount); if (item != null) { fd.freeInventory.GetInventoryManager().GetDefaultInventory().AddItem((ISkillArgs)args, item, true); } } } else { FreeItem item = FreeItemManager.GetItem((FreeRuleEventArgs)args, FreeItemConfig.GetItemKey((int)ECategory.GameItem, clipType), count); if (item != null) { fd.freeInventory.GetInventoryManager().GetInventory(ChickenConstant.BagGround).AddItem((ISkillArgs)args, item, true); } } }