private void PlayerBuy(UserToken token, MSGModel message) { ulong msg = message.GetMessage <ulong>(); ulong mask = 0xff; ulong worldID = msg & mask; ulong equipmentnum = (msg >> 8) & mask; ulong gold = (msg >> 16); HeroActorModel ham = room.worldAcotr[(int)worldID] as HeroActorModel; Equipment eq = EquipmentCache.Instance.GetEquipmentByID((int)equipmentnum); if (eq != null && gold <= (ulong)ham.Gold && ham.Gold >= eq.Price && ham.package.Count < 6) { ham.Gold = ham.Gold - eq.Price; ham.package.Add((int)equipmentnum); uint id = (uint)worldID; uint speed = (uint)eq.Speed; uint defence = (uint)eq.Defence; uint attack = (uint)eq.Attack; uint hp = (uint)eq.HP; ham.Speed += eq.Speed; ham.Defence += eq.Defence; ham.Attack += eq.Attack; ham.HP += eq.HP; uint cmd = (hp << 16) | (attack << 12) | (defence << 8) | (speed << 4) | id; room.Write(token, Protocol.TYPE_FIGHT, Protocol.AREA_S_RES_BUY_SUCCESS, ham.Gold, null); room.Brocast(Protocol.TYPE_FIGHT, Protocol.AREA_S_PLAYER_BUY, (int)cmd, null, null); } }
private void SendHeroData(UserToken token, MSGModel message) { int wolrdID = message.GetMessage <int>(); HeroActorModel ham = room.worldAcotr[wolrdID] as HeroActorModel; HeroData data = HeroDataFactory.CreateHeroData(ham); room.Write(token, Protocol.TYPE_FIGHT, Protocol.AREA_S_RES_HERODATA, 0, data); }
public static HeroData CreateHeroData(HeroActorModel ha) { HeroData hd = new HeroData(); hd.WorldID = ha.id; hd.HP = ha.HP; hd.Attack = ha.Attack; hd.Defence = ha.Defence; hd.Speed = ha.Speed; hd.Level = ha.Level; hd.Exp = ha.Exp; hd.Gold = ha.Gold; hd.MaxExp = ha.MaxExp; hd.MaxHP = ha.MaxHP; return(hd); }
private void AddGold(UserToken token, MSGModel message) { int msg = message.GetMessage <int>(); int targetGold = msg >> 10; int worldID = msg & 1023; HeroActorModel heroModel = room.worldAcotr[worldID] as HeroActorModel; if (heroModel.Gold == targetGold - 1) {//验证通过 (room.worldAcotr[worldID] as HeroActorModel).Gold = targetGold; room.Write(token, Protocol.TYPE_FIGHT, Protocol.AREA_S_GOLD_TIMEADD_SUCCESS, targetGold, null); } else { //客户端可能开挂了 } }
private void PlayerSell(UserToken token, MSGModel message) { int mask = 0xff; int msg = message.GetMessage <int>(); int worldID = msg & mask; int equipment = msg >> 8; HeroActorModel ham = room.worldAcotr[worldID] as HeroActorModel; if (ham.package.Contains(equipment)) { Equipment equimentAttribute = EquipmentCache.Instance.GetEquipmentByID(equipment); ham.package.Remove(equipment); ham.Gold += equimentAttribute.Price; ham.HP -= equimentAttribute.HP; ham.Attack -= equimentAttribute.Attack; ham.Defence -= equimentAttribute.Defence; ham.Speed -= equimentAttribute.Speed; uint sellNotifyMsg = (uint)((equimentAttribute.HP << 16) | (equimentAttribute.Attack << 12) | (equimentAttribute.Defence << 8) | (equimentAttribute.Speed << 4) | (worldID)); room.Brocast(Protocol.TYPE_FIGHT, Protocol.AREA_S_PLAYER_SELL, (int)sellNotifyMsg, null, null); room.Write(token, Protocol.TYPE_FIGHT, Protocol.AREA_S_RES_SELL_SUCCESS, ham.Gold, null); } }
private void HeroReset(int id, HeroActorModel ham) { ham.Reset(); room.Brocast(Protocol.TYPE_FIGHT, Protocol.AREA_S_HERO_RESET, id, null, null); }
private void OnDemageInfo(UserToken token, MSGModel message) { DemageInfo di = message.GetMessage <DemageInfo>(); lock (room.worldAcotr) { AbsActorModel aam = null; if (room.worldAcotr.ContainsKey(di.DemagedID)) { aam = room.worldAcotr[di.DemagedID]; } else//如果世界中没有这个物体则返回 { return; } int HP = -1; HP = aam.GetHP(); if (HP == di.PreHP && HP >= 0) { //可以造成伤害 int defence = aam.GetDefence(); int damage = Math.Max(di.Attack - defence, 2); HP -= damage; aam.SetHP(HP); DemageResult dr = new DemageResult(); dr.RemainHP = HP; dr.TargetID = di.DemagedID; room.Brocast(Protocol.TYPE_FIGHT, Protocol.AREA_S_DEMAGE, 0, dr, null); if (HP <= 0) { //单位被击杀 int killGold = aam.GetKillGold(); //奖励金币 //击杀者为英雄 if (di.Attacker == 0 || di.Attacker == 10) { HeroActorModel ham = room.worldAcotr[di.Attacker] as HeroActorModel; ham.Gold += killGold; room.Write(token, Protocol.TYPE_FIGHT, Protocol.AREA_S_GOLD_TIMEADD_SUCCESS, ham.Gold, null); } if (di.DemagedID == 0 || di.DemagedID == 10) {//英雄死亡 //通知客户端英雄死亡进入死亡状态 HeroActorModel ham_demage = room.worldAcotr[di.DemagedID] as HeroActorModel; room.Brocast(Protocol.TYPE_FIGHT, Protocol.AREA_S_HERO_DEAD, di.DemagedID, ham_demage.ResetTime, null); ScheduleUtil.Instance.Schedule(delegate() { HeroReset(di.DemagedID, ham_demage); }, ham_demage.ResetTime); } else if (di.DemagedID >= 30 && di.DemagedID <= 1029 && room.worldAcotr.ContainsKey(di.DemagedID)) {//被击杀的是小兵 //通知客户端有小兵死亡. //SodierActorModel sam_demage = room.worldAcotr[di.DemagedID] as SodierActorModel; try { AbsActorModel tmp = null; room.worldAcotr.TryRemove(di.DemagedID, out tmp); if (tmp != null) { ((SodierActorModel)tmp).Reset(); } room.sodiersPool.Enqueue(tmp as SodierActorModel); Console.WriteLine("小兵 " + tmp.id + " 死亡"); room.Brocast(Protocol.TYPE_FIGHT, Protocol.AREA_S_SODIER_DEADTH, di.DemagedID, di.Attacker, null); } catch (Exception e) { Console.WriteLine(e.Message); } } } } } }