void OnItemPickuped(GetItemMsg item) { MeteorUnit unit = U3D.GetUnit((int)item.playerId); if (item.type == (int)GetItemType.SceneItem) { SceneItemAgent sceneItem = U3D.GetSceneItem((int)item.instance); if (sceneItem != null) { sceneItem.OnNetPickuped(unit); } } else if (item.type == (int)GetItemType.PickupItem) { PickupItemAgent pickup = U3D.GetPickupItem((int)item.instance); if (pickup != null) { pickup.OnNetPickup(unit); } } }
public void OnPickUped(MeteorUnit unit) { //场景上的模型物件捡取 if (unit.Dead) { return; } if (ItemInfo != null && ItemInfo.Type != 0 && root != null) { if (ItemInfo.IsWeapon()) { //满武器,不能捡 if (unit.Attr.Weapon != 0 && unit.Attr.Weapon2 != 0) { return; } //相同武器,不能捡 ItemData ib0 = GameStateMgr.Ins.FindItemByIdx(unit.Attr.Weapon); WeaponData wb0 = U3D.GetWeaponProperty(ib0.UnitId); if (wb0 != null && wb0.WeaponR == ItemInfo.model) { return; } if (unit.Attr.Weapon2 != 0) { ItemData ib1 = GameStateMgr.Ins.FindItemByIdx(unit.Attr.Weapon2); WeaponData wb1 = U3D.GetWeaponProperty(ib1.UnitId); if (wb1 != null && wb1.WeaponR == ItemInfo.model) { return; } } //同类武器不能捡 int weaponPickup = GameStateMgr.Ins.GetWeaponCode(ItemInfo.model); ItemData wb = GameStateMgr.Ins.FindItemByIdx(weaponPickup); if (wb == null) { return; } ItemData wbl = GameStateMgr.Ins.FindItemByIdx(unit.Attr.Weapon); if (wbl == null) { return; } ItemData wbr = GameStateMgr.Ins.FindItemByIdx(unit.Attr.Weapon2); if (wb.SubType == wbl.SubType) { return; } if (wbr != null && wb.SubType == wbr.SubType) { return; } //可以捡取 unit.Attr.Weapon2 = weaponPickup; SFXLoader.Ins.PlayEffect(672, unit.gameObject, true); refresh_tick = ItemInfo.first[1].flag[1]; if (asDrop) { GameObject.Destroy(gameObject); } else { if (refresh_tick > 0) { Refresh = true; } GameObject.Destroy(root.gameObject); root = null; } } else if (ItemInfo.IsItem()) { //表明此为Buff,会叠加某个属性,且挂上一个持续的特效。 unit.GetItem(ItemInfo); refresh_tick = ItemInfo.first[1].flag[1]; if (refresh_tick > 0) { Refresh = true; } GameObject.Destroy(root.gameObject); root = null; } else if (ItemInfo.IsFlag()) { GameObject.Destroy(root.gameObject); root = null; if (ItemInfo.first[1].flag[1] != 0) { SFXLoader.Ins.PlayEffect(ItemInfo.first[1].flag[1], unit.gameObject, true); } U3D.InsertSystemMsg(unit.name + " 夺得镖物"); unit.SetFlag(ItemInfo, ItemInfo.first[2].flag[1]); } if (OnPickUp != null) { OnPickUp.Invoke(CombatData.Ins.GScript, null); } } else if (ItemInfoEx != null) { if (ItemInfoEx.MainType == (int)UnitType.Weapon) { string weaponModel = ""; WeaponData wp = U3D.GetWeaponProperty(ItemInfoEx.UnitId); if (wp != null) { weaponModel = wp.WeaponR; } //满武器,不能捡 if (unit.Attr.Weapon != 0 && unit.Attr.Weapon2 != 0) { return; } //相同武器,不能捡 ItemData ib0 = GameStateMgr.Ins.FindItemByIdx(unit.Attr.Weapon); WeaponData wb0 = U3D.GetWeaponProperty(ib0.UnitId); if (wb0 != null && wb0.WeaponR == weaponModel) { return; } if (unit.Attr.Weapon2 != 0) { ItemData ib1 = GameStateMgr.Ins.FindItemByIdx(unit.Attr.Weapon2); WeaponData wb1 = U3D.GetWeaponProperty(ib1.UnitId); if (wb1 != null && wb1.WeaponR == weaponModel) { return; } } //同类武器不能捡 int weaponPickup = GameStateMgr.Ins.GetWeaponCode(weaponModel); ItemData wb = GameStateMgr.Ins.FindItemByIdx(weaponPickup); if (wb == null) { return; } ItemData wbl = GameStateMgr.Ins.FindItemByIdx(unit.Attr.Weapon); if (wbl == null) { return; } ItemData wbr = GameStateMgr.Ins.FindItemByIdx(unit.Attr.Weapon2); if (wb.SubType == wbl.SubType) { return; } if (wbr != null && wb.SubType == wbr.SubType) { return; } //可以捡取 unit.Attr.Weapon2 = weaponPickup; SFXLoader.Ins.PlayEffect(672, unit.gameObject, true); if (asDrop) { GameObject.Destroy(gameObject); } } } else { if (OnTouch != null) { OnTouch.Invoke(CombatData.Ins.GScript, new object[] { 0, unit.InstanceId }); } else if (OnPickUp != null) { OnPickUp.Invoke(CombatData.Ins.GScript, null); } } if (unit.Attr.IsPlayer && CombatData.Ins.GLevelMode == LevelMode.MultiplyPlayer) { GetItemMsg msg = new GetItemMsg(); msg.instance = (uint)InstanceId; msg.playerId = (uint)unit.InstanceId; msg.type = (int)GetItemType.SceneItem; FrameSyncServer.Ins.NetEvent(protocol.MeteorMsg.Command.GetItem, msg); } }
public override void Update() { for (int i = 0; i < packets.Count; i++) { SortedDictionary <int, byte[]> pack = packets[i]; lock (pack) { try { //在这个循环里,不能跑去修改这个packet,所有重要消息,都通过计时器处理. foreach (var each in pack) { ms.SetLength(0); ms.Write(each.Value, 0, each.Value.Length); ms.Seek(0, SeekOrigin.Begin); switch (each.Key) { //UDP消息 case (int)MeteorMsg.Command.ServerSync: GameFrame frame = Serializer.Deserialize <GameFrame>(ms); OnSyncPlayers(frame); break; case (int)MeteorMsg.Command.NewTurn: if (!FrameReplay.Ins.Started) { return; } if (Main.Ins.GameBattleEx != null) { Main.Ins.GameBattleEx.NetGameOver(); } break; case (int)MeteorMsg.Command.GetItem: //ms = new MemoryStream(each.Value); GetItemMsg getitem = Serializer.Deserialize <GetItemMsg>(ms); OnItemPickuped(getitem); break; case (int)MeteorMsg.Command.Drop: //ms = new MemoryStream(each.Value); DropMsg dropItem = Serializer.Deserialize <DropMsg>(ms); OnItemDropped(dropItem); break; case (int)MeteorMsg.Command.Kill: //ms = new MemoryStream(each.Value); OperateMsg kill = Serializer.Deserialize <OperateMsg>(ms); Kill(kill); break; case (int)MeteorMsg.Command.Kick: //ms = new MemoryStream(each.Value); OperateMsg kick = Serializer.Deserialize <OperateMsg>(ms); OnKicked(kick); break; case (int)MeteorMsg.Command.Skick: //ms = new MemoryStream(each.Value); OperateMsg skick = Serializer.Deserialize <OperateMsg>(ms); OnSkicked(skick); break; } } } catch (Exception exp) { UnityEngine.Debug.LogError(exp.Message + exp.StackTrace); } finally { pack.Clear(); } } } //lock (messageQueue) { // int length = messageQueue.Count; // for (int i = 0; i < length; i++) { // switch (messageQueue[i].Message) { // case (short)LocalMsgType.Connect: OnConnect(messageQueue[i].Result, messageQueue[i].message); break; // } // } // messageQueue.Clear(); //} }
public void OnPickup(MeteorUnit unit) { if (unit != null && !unit.Dead) { //满武器,不能捡 if (unit.Attr.Weapon != 0 && unit.Attr.Weapon2 != 0) { return; } //相同武器,不能捡 ItemData ib0 = GameStateMgr.Ins.FindItemByIdx(unit.Attr.Weapon); WeaponData wb0 = U3D.GetWeaponProperty(ib0.UnitId); if (wb0 != null && wb0.WeaponR == model) { return; } if (unit.Attr.Weapon2 != 0) { ItemData ib1 = GameStateMgr.Ins.FindItemByIdx(unit.Attr.Weapon2); WeaponData wb1 = U3D.GetWeaponProperty(ib1.UnitId); if (wb1 != null && wb1.WeaponR == model) { return; } } //同类武器不能捡 int weaponPickup = GameStateMgr.Ins.GetWeaponCode(model); ItemData wb = GameStateMgr.Ins.FindItemByIdx(weaponPickup); if (wb == null) { return; } ItemData wbl = GameStateMgr.Ins.FindItemByIdx(unit.Attr.Weapon); if (wbl == null) { return; } ItemData wbr = GameStateMgr.Ins.FindItemByIdx(unit.Attr.Weapon2); if (wb.SubType == wbl.SubType) { return; } if (wbr != null && wb.SubType == wbr.SubType) { return; } //可以捡取 unit.Attr.Weapon2 = weaponPickup; SFXLoader.Ins.PlayEffect(672, unit.gameObject, true); if (unit.Attr.IsPlayer && CombatData.Ins.GLevelMode == LevelMode.MultiplyPlayer) { GetItemMsg msg = new GetItemMsg(); msg.instance = (uint)InstanceId; msg.playerId = (uint)unit.InstanceId; msg.type = (int)GetItemType.PickupItem; FrameSyncServer.Ins.NetEvent(protocol.MeteorMsg.Command.GetItem, msg); } Destroy(gameObject); } }