private void handleFromGround(string from, string to, ServerRoom room, FreeData fd) { if (from.StartsWith(Ground) && !to.StartsWith(Ground)) { SimpleItemInfo info = PickupItemUtil.GetGroundItemInfo(room, fd, from); if (info.cat > 0) { ItemInventory inv = fd.freeInventory.GetInventoryManager().GetInventory("ground"); if (inv != null) { inv.Clear(); FreeItem item = FreeItemManager.GetItem(room.FreeArgs, FreeItemConfig.GetItemKey(info.cat, info.id), info.count); item.GetParameters().AddPara(new IntPara("entityId", info.entityId)); inv.AddItem(room.FreeArgs, item, false); DragGroundOne(fd, room, to); } else { Debug.LogErrorFormat("inventory {0} not existed.", from); } } } }
private void onFind(IGameEntity localEntity) { if (localEntity.EntityType != 6) { return; } SceneObjectEntity entity = fr.GameContext.sceneObject.GetEntityWithEntityKey(localEntity.EntityKey); if (entity != null && entity.hasSimpleItem && entity.simpleItem != null) { if (IsNear(entity.position.Value, _playerEntity.position.Value)) { CreateItemToPlayerAction action = new CreateItemToPlayerAction(); action.key = FreeItemConfig.GetItemKey(entity.simpleItem.Category, entity.simpleItem.Id); action.name = ChickenConstant.BagGround; if (!string.IsNullOrEmpty(action.key)) { action.count = entity.simpleItem.Count.ToString(); action.SetPlayer("current"); fr.TempUse("current", (FreeData)_playerEntity.freeData.FreeData); action.Act(fr); if (_ground.posList.Count > 0) { ItemPosition lastItem = _ground.posList[_ground.posList.Count - 1]; lastItem.GetKey().GetParameters() .AddPara(new IntPara("entityId", entity.entityKey.Value.EntityId)); } fr.Resume("current"); } } } }
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); } } }
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); bool canAdd = true; if (action.name == "default") { canAdd = BagCapacityUtil.CanAddToBag(room.FreeArgs, fd, item.cat, item.id, count); } if (canAdd) { PlayerAnimationAction.DoAnimation(room.RoomContexts, PlayerAnimationAction.Interrupt, fd.Player, true); PlayerAnimationAction.DoAnimation(room.RoomContexts, 101, fd.Player, true); if (!string.IsNullOrEmpty(action.key)) { action.count = count.ToString(); action.SetPlayer("current"); room.FreeArgs.TempUse("current", fd); action.Act(room.FreeArgs); room.FreeArgs.Resume("current"); } 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"); }
public static bool AddItemToPlayer(ServerRoom room, PlayerEntity player, int entityId, int cat, int id, int count, string toInv = "") { SceneObjectEntity entity = room.RoomContexts.sceneObject.GetEntityWithEntityKey(new EntityKey(entityId, (short)EEntityType.SceneObject)); FreeMoveEntity freeMoveEntity = null; if (entity == null || entity.isFlagDestroy) { freeMoveEntity = room.RoomContexts.freeMove.GetEntityWithEntityKey(new EntityKey(entityId, (short)EEntityType.FreeMove)); if (freeMoveEntity == null) { return(false); } } FreeData fd = (FreeData)player.freeData.FreeData; room.ContextsWrapper.FreeArgs.TempUse("current", fd); if (!FreeItemConfig.Contains(cat, id)) { return(false); } FreeItemInfo item = FreeItemConfig.GetItemInfo(cat, id); CreateItemToPlayerAction action = new CreateItemToPlayerAction(); action.name = ChickenConstant.BagDefault; switch (item.cat) { case (int)ECategory.Weapon: if (item.subType == ChickenConstant.ItemCatPrimeWeapon) { action.name = ChickenConstant.BagPrimeWeapon; int c1 = fd.freeInventory.GetInventoryManager().GetInventory(ChickenConstant.BagPrimeWeapon).posList.Count; int c2 = fd.freeInventory.GetInventoryManager().GetInventory(ChickenConstant.BagSecondaryWeapon).posList.Count; if (toInv.StartsWith(ChickenConstant.BagPrimeWeapon)) { action.name = ChickenConstant.BagPrimeWeapon; if (c1 > 0) { DropItem(action.name, fd, room); } } else if (toInv.StartsWith(ChickenConstant.BagSecondaryWeapon)) { action.name = ChickenConstant.BagSecondaryWeapon; if (c2 > 0) { DropItem(action.name, fd, room); } } else { if (c1 > 0 && c2 == 0) { action.name = ChickenConstant.BagSecondaryWeapon; } 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 = ChickenConstant.BagPrimeWeapon; } DropItem(action.name, fd, room); } } } else if (item.subType == ChickenConstant.ItemCatPistolWeapon) { action.name = ChickenConstant.BagPistolWeapon; DropItem(action.name, fd, room); } else if (item.subType == ChickenConstant.ItemCatMeleeWeapon) { action.name = ChickenConstant.BagMeleeWeapon; DropItem(action.name, fd, room); } else if (item.subType == ChickenConstant.ItemCatGrenadeWeapon) { action.name = ChickenConstant.BagDefault; } else if (item.subType == ChickenConstant.ItemCatArmor) { action.name = ChickenConstant.BagArmor; if (entity != null) { count = entity.armorDurability.CurDurability; } DropItem(action.name, fd, room); } else if (item.subType == ChickenConstant.ItemCatHelmet) { action.name = ChickenConstant.BagHelmet; if (entity != null) { count = entity.armorDurability.CurDurability; } DropItem(action.name, fd, room); } 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; } action.key = FreeItemConfig.GetItemKey(item.cat, item.id); int canCount = 0; if (action.name == ChickenConstant.BagDefault) { canCount = BagCapacityUtil.CanAddToBagCount(room.ContextsWrapper.FreeArgs, fd, item.cat, item.id, count); } else if (item.type == ChickenConstant.ItemCatAvatar || action.name == ChickenConstant.BagHelmet || action.name == ChickenConstant.BagArmor) { canCount = count; } else { canCount = 1; } bool pickupSuccess = false; if (canCount > 0 && !string.IsNullOrEmpty(action.name)) { PlayerAnimationAction.DoAnimation(room.RoomContexts, PlayerAnimationAction.Interrupt, fd.Player, true); PlayerAnimationAction.DoAnimation(room.RoomContexts, PlayerAnimationAction.PickUp, fd.Player, true); PlayerStateUtil.AddPlayerState(EPlayerGameState.InterruptItem, fd.Player.gamePlay); if (!string.IsNullOrEmpty(action.key)) { action.count = canCount.ToString(); action.SetPlayer("current"); room.ContextsWrapper.FreeArgs.TempUse("current", fd); action.Act(room.ContextsWrapper.FreeArgs); room.ContextsWrapper.FreeArgs.Resume("current"); if (count > canCount) { SimpleProto msg = FreePool.Allocate(); msg.Key = FreeMessageConstant.ChickenTip; msg.Ss.Add("word80," + count + "," + canCount); FreeMessageSender.SendMessage(fd.Player, msg); room.ContextsWrapper.FreeArgs.GameContext.session.entityFactoryObject.SceneObjectEntityFactory.CreateSimpleObjectEntity((ECategory)item.cat, item.id, count - canCount, entity == null ? freeMoveEntity.position.Value : entity.position.Value); } pickupSuccess = true; } else { Debug.LogError(item.cat + "-" + item.key + " not existed"); } if (entity != null) { entity.isFlagDestroy = true; } if (freeMoveEntity != null) { freeMoveEntity.isFlagDestroy = true; if (freeMoveEntity.freeData.Cat == FreeEntityConstant.DeadBox) { var deadBox = room.ContextsWrapper.FreeArgs.GameContext.freeMove.GetEntityWithEntityKey(new EntityKey(freeMoveEntity.freeData.IntValue, (short)EEntityType.FreeMove)); if (deadBox != null && deadBox.freeData.EmptyDelete) { if (deadBox.freeData.IntValue > 1) { deadBox.freeData.IntValue--; } else { deadBox.isFlagDestroy = true; } } } } } room.ContextsWrapper.FreeArgs.Resume("current"); return(pickupSuccess); }