public override void DoAction(IEventArgs args) { if (inter) { if (fd != null) { fd.freeInventory.StopUseItem(args, fd); UseCommonAction use = new UseCommonAction(); use.key = "showBottomTip"; use.values = new List <ArgValue>(); use.values.Add(new ArgValue("msg", "{desc:10072,{item.name}}")); args.TempUse("current", fd); args.TempUse("item", ip); use.Act(args); args.Resume("current"); args.Resume("item"); PlayerAnimationAction.DoAnimation(PlayerAnimationAction.Stop, fd.Player); FreeSoundUtil.Stop("use", args, fd); PlayerStateUtil.RemoveGameState(EPlayerGameState.InterruptItem, fd.Player.gamePlay); } } else { if (ip != null && fd != null) { UseItem(ip, fd, (ISkillArgs)args); fd.freeInventory.StopUseItem(args, fd); } } }
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); }
private void HandleBagWeight(IEventArgs args) { if ("BagWeight" == code) { FreeData fd = (FreeData)args.GetUnit("current"); if (fd != null) { UseCommonAction use = new UseCommonAction(); use.key = "updateBagCapacity"; use.values = new List <ArgValue>(); use.values.Add(new ArgValue("weight", ((int)Math.Ceiling(BagCapacityUtil.GetWeight(fd))).ToString())); use.values.Add(new ArgValue("capacity", BagCapacityUtil.GetCapacity(fd).ToString())); use.Act(args); } } }
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); }
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); }
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 AddItemToPlayer(ServerRoom room, PlayerEntity player, int entityId, int cat, int id, int count, string toInv = "") { SceneObjectEntity entity = room.RoomContexts.sceneObject.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(entityId, (short)EEntityType.SceneObject)); FreeMoveEntity freeMoveEntity = null; if (entity == null || entity.isFlagDestroy) { freeMoveEntity = room.RoomContexts.freeMove.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(entityId, (short)EEntityType.FreeMove)); if (freeMoveEntity == null) { return; } } room.FreeArgs.TempUse("current", (FreeData)player.freeData.FreeData); if (!FreeItemConfig.Contains(cat, id)) { return; } FreeItemInfo item = FreeItemConfig.GetItemInfo(cat, id); CreateItemToPlayerAction action = new CreateItemToPlayerAction(); FreeData fd = (FreeData)player.freeData.FreeData; action.name = "default"; switch (item.cat) { case (int)ECategory.Weapon: if (item.subType == "w1") { action.name = "w1"; int c1 = fd.freeInventory.GetInventoryManager().GetInventory("w1").posList.Count; int c2 = fd.freeInventory.GetInventoryManager().GetInventory("w2").posList.Count; if (toInv.StartsWith("w1")) { action.name = "w1"; if (c1 > 0) { DropItem(action.name, fd, room); } } else if (toInv.StartsWith("w2")) { action.name = "w2"; if (c2 > 0) { DropItem(action.name, fd, room); } } else { if (c1 > 0 && c2 == 0) { action.name = "w2"; } if (c1 > 0 && c2 > 0) { int currentKey = FreeWeaponUtil.GetWeaponKey(fd.Player.WeaponController().HeldSlotType); if (currentKey == 0) { currentKey = 1; } if (currentKey == 1 || currentKey == 2) { action.name = "w" + currentKey; } else { action.name = "w1"; } DropItem(action.name, fd, room); } } } else if (item.subType == "w2") { action.name = "w3"; DropItem(action.name, fd, room); } else if (item.subType == "w3") { action.name = "w4"; DropItem(action.name, fd, room); } else if (item.subType == "w4") { action.name = "default"; } break; case (int)ECategory.Avatar: action.name = item.subType; DropItem(item.subType, fd, room); break; case (int)ECategory.WeaponPart: action.name = AutoPutPart(fd, item, toInv, room); break; default: break; } //handleDropOne(new string[] { "w2" }, action, item, fd, room, entity); //handleAddToDefault(new string[] { "p1", "p2", "p3", "p4", "p5" }, action, item, fd, room, entity); action.key = FreeItemConfig.GetItemKey(item.cat, item.id); int canCount = 0; if (action.name == "default") { canCount = BagCapacityUtil.CanAddToBagCount(room.FreeArgs, fd, item.cat, item.id, count); } else { canCount = 1; } if (canCount > 0) { PlayerAnimationAction.DoAnimation(room.RoomContexts, PlayerAnimationAction.Interrupt, fd.Player, true); PlayerAnimationAction.DoAnimation(room.RoomContexts, 101, fd.Player, true); if (!string.IsNullOrEmpty(action.key)) { action.count = canCount.ToString(); action.SetPlayer("current"); room.FreeArgs.TempUse("current", fd); action.Act(room.FreeArgs); room.FreeArgs.Resume("current"); if (count > canCount) { UseCommonAction use = new UseCommonAction(); use.key = "showBottomTip"; use.values = new List <ArgValue>(); use.values.Add(new ArgValue("msg", "拾取了" + count + "个中的" + canCount + "个")); room.FreeArgs.TempUse("current", fd); use.Act(room.FreeArgs); room.FreeArgs.Resume("current"); room.FreeArgs.GameContext.session.entityFactoryObject.SceneObjectEntityFactory. CreateSimpleEquipmentEntity((ECategory)item.cat, item.id, (count - canCount), entity.position.Value); } } else { Debug.LogError(item.cat + "-" + item.key + " not existed"); } if (entity != null) { entity.isFlagDestroy = true; } if (freeMoveEntity != null) { freeMoveEntity.isFlagDestroy = true; } //Debug.LogErrorFormat("destroy entity {0}", entity != null); FreeSoundUtil.PlayOnce("pick", 225, room.FreeArgs, fd); } room.FreeArgs.Resume("current"); }