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 = WeaponPartUtil.GetWeaponFstMatchedPartId(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); }
/// <summary> /// API:parts /// </summary> /// <param name="slot"></param> /// <param name="survivalCfgId"></param> /// <returns></returns> public bool SetWeaponPart(EWeaponSlotType slot, int survivalCfgId) { var agent = GetWeaponAgent(slot); if (!agent.IsValid()) { return(false); } int matchedPartId = WeaponPartUtil.GetWeaponFstMatchedPartId(survivalCfgId, agent.ResConfig.Id); return(SetWeaponPartByPartId(slot, matchedPartId)); }
public static bool CanDemountAttachment(ServerRoom room, FreeData fd, FreeItemInfo part, string ipStr, bool toGround) { double capacity = Math.Round(GetCapacity(fd) - GetWeight(fd), 3); float bulletWeight = 0f; WeaponBaseAgent agent = fd.Player.WeaponController().GetWeaponAgent((EWeaponSlotType)short.Parse(ipStr.Substring(1, 1))); int overBullet = 0; if (SingletonManager.Get <WeaponPartsConfigManager>().GetConfigById(WeaponPartUtil.GetWeaponFstMatchedPartId(part.id, agent.ConfigId)).Bullet > 0) { overBullet = agent.BaseComponent.Bullet - agent.WeaponConfigAssy.PropertyCfg.Bullet; if (overBullet > 0) { bulletWeight = SingletonManager.Get <GameItemConfigManager>().GetConfigById((int)agent.Caliber).Weight *overBullet; } } var partWeight = 0f; if (!toGround) { partWeight = part.weight; } if (capacity < bulletWeight + partWeight) { SimpleProto msg = FreePool.Allocate(); msg.Key = FreeMessageConstant.ChickenTip; msg.Ss.Add("word79"); FreeMessageSender.SendMessage(fd.Player, msg); return(false); } if (overBullet > 0) { agent.BaseComponent.Bullet = agent.WeaponConfigAssy.PropertyCfg.Bullet; CarryClipUtil.AddClip(overBullet, (int)agent.Caliber, fd, room.ContextsWrapper.FreeArgs); fd.Player.WeaponController().SetReservedBullet(agent.Caliber, CarryClipUtil.GetClipCount((int)agent.Caliber, fd, room.ContextsWrapper.FreeArgs)); } return(true); }
public static bool CanExchangeAttachment(ServerRoom room, FreeData fd, FreeItemInfo fromPart, FreeItemInfo toPart, WeaponBaseAgent fromAgent, WeaponBaseAgent toAgent) { double capacity = Math.Round(GetCapacity(fd) - GetWeight(fd), 3); int toBullet = SingletonManager.Get <WeaponPartsConfigManager>().GetConfigById(WeaponPartUtil.GetWeaponFstMatchedPartId(toPart.id, fromAgent.ConfigId)).Bullet; int fromBullet = SingletonManager.Get <WeaponPartsConfigManager>().GetConfigById(WeaponPartUtil.GetWeaponFstMatchedPartId(fromPart.id, toAgent.ConfigId)).Bullet; if (toBullet == fromBullet) { return(true); } int overBulletFrom = fromAgent.BaseComponent.Bullet - fromAgent.WeaponConfigAssy.PropertyCfg.Bullet - toBullet; int overBulletTo = toAgent.BaseComponent.Bullet - toAgent.WeaponConfigAssy.PropertyCfg.Bullet - fromBullet; float bulletWeight = 0f; if (overBulletFrom > 0) { bulletWeight += SingletonManager.Get <GameItemConfigManager>().GetConfigById((int)fromAgent.Caliber).Weight *overBulletFrom; } if (overBulletTo > 0) { bulletWeight += SingletonManager.Get <GameItemConfigManager>().GetConfigById((int)toAgent.Caliber).Weight *overBulletTo; } if (capacity < bulletWeight) { SimpleProto msg = FreePool.Allocate(); msg.Key = FreeMessageConstant.ChickenTip; msg.Ss.Add("word79"); FreeMessageSender.SendMessage(fd.Player, msg); return(false); } if (overBulletFrom > 0) { fromAgent.BaseComponent.Bullet = fromAgent.WeaponConfigAssy.PropertyCfg.Bullet + toBullet; CarryClipUtil.AddClip(overBulletFrom, (int)fromAgent.Caliber, fd, room.ContextsWrapper.FreeArgs); fd.Player.WeaponController().SetReservedBullet(fromAgent.Caliber, CarryClipUtil.GetClipCount((int)fromAgent.Caliber, fd, room.ContextsWrapper.FreeArgs)); } if (overBulletTo > 0) { toAgent.BaseComponent.Bullet = toAgent.WeaponConfigAssy.PropertyCfg.Bullet + fromBullet; CarryClipUtil.AddClip(overBulletTo, (int)toAgent.Caliber, fd, room.ContextsWrapper.FreeArgs); fd.Player.WeaponController().SetReservedBullet(toAgent.Caliber, CarryClipUtil.GetClipCount((int)toAgent.Caliber, fd, room.ContextsWrapper.FreeArgs)); } return(true); }
public void Handle(ServerRoom room, PlayerEntity player, SimpleProto message) { FreeData fd = (FreeData)player.freeData.FreeData; var freeArgs = room.ContextsWrapper.FreeArgs as FreeRuleEventArgs; freeArgs.TempUse(PARA_PLAYER_CURRENT, fd); eventKey.SetValue(message.Ss[0]); freeArgs.GetDefault().GetParameters().TempUse(eventKey); Debug.Log("drag from:" + message.Ss[0] + " to:" + message.Ss[1]); string from = message.Ss[0]; string to = message.Ss[1]; ItemPosition fromIp = FreeItemManager.GetItemPosition(freeArgs, from, fd.freeInventory.GetInventoryManager()); ItemPosition toIp = FreeItemManager.GetItemPosition(freeArgs, to, fd.freeInventory.GetInventoryManager()); // 显示拆分UI if (message.Bs[0] && from.StartsWith(ChickenConstant.BagDefault)) { PickupItemUtil.ShowSplitUI(room, fd, from); } else if (!HandleBag(from, to, room, fd)) { } else if (player.gamePlay.GameState == GameState.AirPlane || player.gamePlay.GameState == GameState.Gliding || player.gamePlay.GameState == GameState.JumpPlane) { } /*else if (from.StartsWith(ChickenConstant.BagBelt) || to.StartsWith(ChickenConstant.BagBelt)) * { * // 腰包不能做任何操作 * SimpleProto msg = FreePool.Allocate(); * msg.Key = FreeMessageConstant.ChickenTip; * msg.Ss.Add("word63"); * FreeMessageSender.SendMessage(fd.Player, msg); * }*/ else if (from.StartsWith(ChickenConstant.BagGround) && !to.StartsWith(ChickenConstant.BagGround)) { // 地面模糊操作 HandleAuto(from, to, room, fd); } else if (from.StartsWith(ChickenConstant.BagGround) || to.StartsWith(ChickenConstant.BagGround)) { /*if (from.StartsWith(Ground) && !to.StartsWith(Ground)) * { * handleFromGround(from, to, room, fd); * }*/ if (!from.StartsWith(ChickenConstant.BagGround) && to.StartsWith(ChickenConstant.BagGround)) { FreeItemInfo fromInfo = FreeItemConfig.GetItemInfo(fromIp.key.GetKey()); if (fromInfo.cat == (int)ECategory.WeaponPart && from.StartsWith("w")) { if (BagCapacityUtil.CanDemountAttachment(room, fd, fromInfo, from, true)) { handleToGround(from, to, room, fd); } } else { handleToGround(from, to, room, fd); } } } else if (from.StartsWith(ChickenConstant.BagDefault) && to.StartsWith("w")) { // 背包物品拖动到武器槽 if (fromIp != null) { FreeItemInfo info = FreeItemConfig.GetItemInfo(fromIp.key.GetKey()); if (info.cat == (int)ECategory.WeaponPart) { MovePartToWeapon(room, fd, fromIp, to, info); } else { FreeItemManager.DragItem(from, fd, room.ContextsWrapper.FreeArgs, to); } } } else if (PickupItemUtil.IsDefault(from) && string.IsNullOrEmpty(to)) { // 背包物品拖动到人身上 if (fromIp != null) { FreeItemInfo info = FreeItemConfig.GetItemInfo(fromIp.key.GetKey()); if (info.cat == (int)ECategory.WeaponPart) { MovePartToWeapon(room, fd, fromIp, to, info); } else { FreeItemManager.UseItem(from, fd, room.ContextsWrapper.FreeArgs); } } } else if ((from.StartsWith("w1,") && to.StartsWith("w2,")) || (from.StartsWith("w2,") && to.StartsWith("w1,"))) { ExchangeWeapon(room.ContextsWrapper.FreeArgs, fd, from, to); } else if (from.StartsWith("w") && to.StartsWith("w") && from.IndexOf(",") == 3 && to.IndexOf(",") == 2) { if (fromIp != null && toIp != null) { WeaponBaseAgent toAgent = fd.Player.WeaponController().GetWeaponAgent((EWeaponSlotType)short.Parse(to.Substring(1, 1))); FreeItemInfo fromInfo = FreeItemConfig.GetItemInfo(fromIp.key.GetKey()); if (!toAgent.WeaponConfigAssy.IsPartMatchWeapon(WeaponPartUtil.GetWeaponFstMatchedPartId(fromInfo.id, toAgent.ConfigId))) { SimpleProto msg = FreePool.Allocate(); msg.Key = FreeMessageConstant.ChickenTip; msg.Ss.Add("word77," + toAgent.WeaponConfigAssy.S_Name + "," + fromInfo.name); FreeMessageSender.SendMessage(fd.Player, msg); } else { string toPosition = to.Substring(0, 2) + from.Substring(2, 1) + ",0,0"; ItemPosition toPart = FreeItemManager.GetItemPosition(room.ContextsWrapper.FreeArgs, toPosition, fd.freeInventory.GetInventoryManager()); WeaponBaseAgent fromAgent = fd.Player.WeaponController().GetWeaponAgent((EWeaponSlotType)short.Parse(from.Substring(1, 1))); if (toPart != null) { FreeItemInfo toInfo = FreeItemConfig.GetItemInfo(toPart.key.GetKey()); if (!fromAgent.WeaponConfigAssy.IsPartMatchWeapon(WeaponPartUtil.GetWeaponFstMatchedPartId(toInfo.id, fromAgent.ConfigId))) { SimpleProto msg = FreePool.Allocate(); msg.Key = FreeMessageConstant.ChickenTip; msg.Ss.Add("word77," + fromAgent.WeaponConfigAssy.S_Name + "," + toInfo.name); FreeMessageSender.SendMessage(fd.Player, msg); } else { if (BagCapacityUtil.CanExchangeAttachment(room, fd, fromInfo, toInfo, fromAgent, toAgent)) { FreeItemManager.DragItem(from, fd, room.ContextsWrapper.FreeArgs, toPosition); } } } else { if (BagCapacityUtil.CanDemountAttachment(room, fd, fromInfo, from, false)) { FreeItemManager.DragItem(from, fd, room.ContextsWrapper.FreeArgs, toPosition); } } } } } else if (from.StartsWith("w") && from.IndexOf(",") == 3 && PickupItemUtil.IsDefault(to)) { FreeItemInfo fromInfo = FreeItemConfig.GetItemInfo(fromIp.key.GetKey()); if (BagCapacityUtil.CanDemountAttachment(room, fd, fromInfo, from, false)) { ItemInventory fromInv = fromIp.GetInventory(); ItemInventory toInv = toIp == null?fd.freeInventory.GetInventoryManager().GetInventory(ChickenConstant.BagDefault) : toIp.GetInventory(); int[] pos = toIp == null ? new int[] { 0, 0 } : toInv.GetNextEmptyPosition(toIp.GetKey()); ItemInventoryUtil.MoveItem(pos[0], pos[1], fromInv, toInv, fromInv.GetInventoryUI(), toInv.GetInventoryUI(), fromIp, null, room.ContextsWrapper.FreeArgs); } } else { FreeItemManager.DragItem(from, fd, room.ContextsWrapper.FreeArgs, to); } room.ContextsWrapper.FreeArgs.Resume(PARA_PLAYER_CURRENT); room.ContextsWrapper.FreeArgs.GetDefault().GetParameters().Resume(PARA_EVENT_KEY); }