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 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); }