public static bool CanAttack(GameClient client, BiaoCheItem enemy) { bool result; if (null == enemy) { result = false; } else if (enemy.YaBiaoID == BiaoCheManager.NotAttackYaBiaoID) { result = false; } else { int maxlevel = (enemy.MaxLevel < 0) ? 1000 : enemy.MaxLevel; result = (client.ClientData.Level <= maxlevel); } return(result); }
private static void RemoveBiaoChe(int biaoCheID) { BiaoCheItem biaoCheItem = null; lock (BiaoCheManager._ID2BiaoCheDict) { BiaoCheManager._ID2BiaoCheDict.TryGetValue(biaoCheID, out biaoCheItem); if (null != biaoCheItem) { BiaoCheManager._ID2BiaoCheDict.Remove(biaoCheItem.BiaoCheID); } } lock (BiaoCheManager._RoleID2BiaoCheDict) { if (null != biaoCheItem) { BiaoCheManager._RoleID2BiaoCheDict.Remove(biaoCheItem.OwnerRoleID); } } }
/// <summary> /// 发送镖车到给自己 /// </summary> /// <param name="client"></param> public static void SendMySelfBiaoCheItems(SocketListener sl, TCPOutPacketPool pool, GameClient client, List <Object> objsList) { if (null == objsList) { return; } BiaoCheItem biaoCheItem = null; for (int i = 0; i < objsList.Count; i++) { if (!(objsList[i] is BiaoCheItem)) { continue; } if ((objsList[i] as BiaoCheItem).CurrentLifeV <= 0) { continue; } biaoCheItem = objsList[i] as BiaoCheItem; GameManager.ClientMgr.NotifyMySelfNewBiaoChe(sl, pool, client, biaoCheItem); } }
/// <summary> /// 处理已经镖车的超时 /// </summary> /// <param name="client"></param> public static void ProcessAllBiaoCheItems(SocketListener sl, TCPOutPacketPool pool) { List <BiaoCheItem> biaoCheItemList = new List <BiaoCheItem>(); lock (_ID2BiaoCheDict) { foreach (var val in _ID2BiaoCheDict.Values) { biaoCheItemList.Add(val); } } long nowTicks = TimeUtil.NOW(); BiaoCheItem biaoCheItem = null; for (int i = 0; i < biaoCheItemList.Count; i++) { biaoCheItem = biaoCheItemList[i]; //处理镖车的超时 if (ProcessBiaoCheOverTime(sl, pool, nowTicks, biaoCheItem)) { continue; } //处理镖车的死亡 if (ProcessBiaoCheDead(sl, pool, nowTicks, biaoCheItem)) { continue; } //处理镖车的加血 ProcessBiaoCheAddLife(sl, pool, nowTicks, biaoCheItem); } }
/// <summary> /// 处理镖车的加血 /// </summary> /// <param name="sl"></param> /// <param name="pool"></param> /// <param name="biaoCheItem"></param> /// <returns></returns> private static void ProcessBiaoCheAddLife(SocketListener sl, TCPOutPacketPool pool, long nowTicks, BiaoCheItem biaoCheItem) { long subTicks = nowTicks - biaoCheItem.LastLifeMagicTick; //如果还没到时间,则跳过 if (subTicks < (5 * 1000)) { return; } biaoCheItem.LastLifeMagicTick = nowTicks; if (biaoCheItem.CurrentLifeV <= 0) { return; } //判断如果血量少于最大血量 if (biaoCheItem.CurrentLifeV < biaoCheItem.LifeV) { double lifeMax = biaoCheItem.CutLifeV; lifeMax += biaoCheItem.CurrentLifeV; if (biaoCheItem.CurrentLifeV > 0) { biaoCheItem.CurrentLifeV = (int)Global.GMin(biaoCheItem.LifeV, lifeMax); List <Object> objList = Global.GetAll9Clients(biaoCheItem); //镖车血变化(同一个地图才需要通知) GameManager.ClientMgr.NotifyOtherBiaoCheLifeV(sl, pool, objList, biaoCheItem.BiaoCheID, biaoCheItem.CurrentLifeV); //GameManager.SystemServerEvents.AddEvent(string.Format("镖车加血, BiaoCheID={0}({1}), Add={2}, Life={3}", biaoCheItem.BiaoCheID, biaoCheItem.BiaoCheName, biaoCheItem.CutLifeV, biaoCheItem.CurrentLifeV), EventLevels.Debug); } } }
/// <summary> /// 处理镖车的死亡 /// </summary> /// <param name="sl"></param> /// <param name="pool"></param> /// <param name="biaoCheItem"></param> /// <returns></returns> private static bool ProcessBiaoCheDead(SocketListener sl, TCPOutPacketPool pool, long nowTicks, BiaoCheItem biaoCheItem) { if (biaoCheItem.CurrentLifeV > 0) { return(false); } long subTicks = nowTicks - biaoCheItem.BiaoCheDeadTicks; //如果还没到时间,则跳过 if (subTicks < (2 * 1000)) { return(false); } ProcessDelBiaoChe(sl, pool, biaoCheItem.BiaoCheID); return(true); }
/// <summary> /// 处理镖车的超时 /// </summary> /// <param name="sl"></param> /// <param name="pool"></param> /// <param name="biaoCheItem"></param> /// <returns></returns> private static bool ProcessBiaoCheOverTime(SocketListener sl, TCPOutPacketPool pool, long nowTicks, BiaoCheItem biaoCheItem) { //判断是否超过了最大的抢时间 if (nowTicks - biaoCheItem.StartTime < Global.MaxYaBiaoTicks) //判断是否删除 { return(false); } ProcessDelBiaoChe(sl, pool, biaoCheItem.BiaoCheID); return(true); }
/// <summary> /// 通知所有人隐藏镖车 /// </summary> public static void NotifyOthersHideBiaoChe(SocketListener sl, TCPOutPacketPool pool, BiaoCheItem biaoCheItem) { if (null == biaoCheItem) { return; } GameManager.MapGridMgr.DictGrids[biaoCheItem.MapCode].RemoveObject(biaoCheItem); //List<Object> objList = Global.GetAll9Clients(biaoCheItem); //GameManager.ClientMgr.NotifyOthersDelBiaoChe(sl, pool, objList, biaoCheItem.BiaoCheID); ; }
public static void NotifyOthersHideBiaoChe(SocketListener sl, TCPOutPacketPool pool, BiaoCheItem biaoCheItem) { if (null != biaoCheItem) { GameManager.MapGridMgr.DictGrids[biaoCheItem.MapCode].RemoveObject(biaoCheItem); } }
private static void ProcessBiaoCheDead(SocketListener sl, TCPOutPacketPool pool, GameClient client, BiaoCheItem biaoCheItem) { if (!biaoCheItem.HandledDead) { biaoCheItem.HandledDead = true; biaoCheItem.BiaoCheDeadTicks = TimeUtil.NOW(); GameClient findClient; if (biaoCheItem.AttackedRoleID >= 0 && biaoCheItem.AttackedRoleID != client.ClientData.RoleID) { findClient = GameManager.ClientMgr.FindClient(biaoCheItem.AttackedRoleID); if (null != findClient) { client = findClient; } } int yinLiang = 0; int experience = 0; int yaJin = 0; Global.GetYaBiaoReward(biaoCheItem.YaBiaoID, out yinLiang, out experience, out yaJin); yinLiang /= 2; experience = 0; int jieBiaoNum = Global.IncTotayJieBiaoNum(client); if (experience > 0) { GameManager.ClientMgr.ProcessRoleExperience(client, (long)experience, true, false, false, "none"); } if (yinLiang > 0) { yinLiang = Global.FilterValue(client, yinLiang); GameManager.ClientMgr.AddUserYinLiang(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, yinLiang, "押镖奖励", false); GameManager.SystemServerEvents.AddEvent(string.Format("角色获取银两, roleID={0}({1}), Money={2}, newMoney={3}", new object[] { client.ClientData.RoleID, client.ClientData.RoleName, client.ClientData.YinLiang, yinLiang }), EventLevels.Record); } GameManager.DBCmdMgr.AddDBCmd(10058, string.Format("{0}:{1}", biaoCheItem.OwnerRoleID, 1), null, client.ServerId); findClient = GameManager.ClientMgr.FindClient(biaoCheItem.OwnerRoleID); if (null != findClient) { if (null != findClient.ClientData.MyYaBiaoData) { findClient.ClientData.MyYaBiaoData.State = 1; GameManager.ClientMgr.NotifyYaBiaoData(findClient); } } else { string gmCmdData = string.Format("-setybstate2 {0} 1", biaoCheItem.OwnerRoleID); GameManager.DBCmdMgr.AddDBCmd(157, string.Format("{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7}:{8}", new object[] { client.ClientData.RoleID, "", 0, "", 0, gmCmdData, 0, 0, -1 }), null, 0); } Global.BroadcastKillBiaoCheHint(client, biaoCheItem); } }
public static int NotifyInjured(SocketListener sl, TCPOutPacketPool pool, GameClient client, BiaoCheItem enemy, int burst, int injure, double injurePercent, int attackType, bool forceBurst, int addInjure, double attackPercent, int addAttackMin, int addAttackMax, double baseRate = 1.0, int addVlue = 0, int nHitFlyDistance = 0) { int ret = 0; if ((enemy as BiaoCheItem).CurrentLifeV > 0) { injure = (enemy as BiaoCheItem).CutLifeV; injure = (int)((double)injure * baseRate + (double)addVlue); injure = (int)((double)injure * injurePercent); ret = injure; (enemy as BiaoCheItem).CurrentLifeV -= injure; (enemy as BiaoCheItem).CurrentLifeV = Global.GMax((enemy as BiaoCheItem).CurrentLifeV, 0); double enemyLife = (double)(enemy as BiaoCheItem).CurrentLifeV; (enemy as BiaoCheItem).AttackedRoleID = client.ClientData.RoleID; GameManager.ClientMgr.SpriteInjure2Blood(sl, pool, client, injure); GameManager.SystemServerEvents.AddEvent(string.Format("镖车减血, Injure={0}, Life={1}", injure, enemyLife), EventLevels.Debug); if ((enemy as BiaoCheItem).CurrentLifeV <= 0) { GameManager.SystemServerEvents.AddEvent(string.Format("镖车死亡, roleID={0}", (enemy as BiaoCheItem).BiaoCheID), EventLevels.Debug); BiaoCheManager.ProcessBiaoCheDead(sl, pool, client, enemy as BiaoCheItem); } if ((enemy as BiaoCheItem).AttackedRoleID >= 0 && (enemy as BiaoCheItem).AttackedRoleID != client.ClientData.RoleID) { GameClient findClient = GameManager.ClientMgr.FindClient((enemy as BiaoCheItem).AttackedRoleID); if (null != findClient) { GameManager.ClientMgr.NotifySpriteInjured(sl, pool, findClient, findClient.ClientData.MapCode, findClient.ClientData.RoleID, (enemy as BiaoCheItem).BiaoCheID, 0, 0, enemyLife, findClient.ClientData.Level, new Point(-1.0, -1.0), 0, EMerlinSecretAttrType.EMSAT_None, 0); ClientManager.NotifySelfEnemyInjured(sl, pool, findClient, findClient.ClientData.RoleID, enemy.BiaoCheID, 0, 0, enemyLife, 0L, 0, EMerlinSecretAttrType.EMSAT_None, 0); } } GameManager.ClientMgr.NotifySpriteInjured(sl, pool, client, client.ClientData.MapCode, client.ClientData.RoleID, (enemy as BiaoCheItem).BiaoCheID, burst, injure, enemyLife, client.ClientData.Level, new Point(-1.0, -1.0), 0, EMerlinSecretAttrType.EMSAT_None, 0); ClientManager.NotifySelfEnemyInjured(sl, pool, client, client.ClientData.RoleID, enemy.BiaoCheID, burst, injure, enemyLife, 0L, 0, EMerlinSecretAttrType.EMSAT_None, 0); if (!client.ClientData.DisableChangeRolePurpleName) { GameManager.ClientMgr.ForceChangeRolePurpleName2(sl, pool, client); } } return(ret); }
private static void ProcessBiaoCheAddLife(SocketListener sl, TCPOutPacketPool pool, long nowTicks, BiaoCheItem biaoCheItem) { long subTicks = nowTicks - biaoCheItem.LastLifeMagicTick; if (subTicks >= 5000L) { biaoCheItem.LastLifeMagicTick = nowTicks; if (biaoCheItem.CurrentLifeV > 0) { if (biaoCheItem.CurrentLifeV < biaoCheItem.LifeV) { double lifeMax = (double)biaoCheItem.CutLifeV; lifeMax += (double)biaoCheItem.CurrentLifeV; if (biaoCheItem.CurrentLifeV > 0) { biaoCheItem.CurrentLifeV = (int)Global.GMin((double)biaoCheItem.LifeV, lifeMax); List <object> objList = Global.GetAll9Clients(biaoCheItem); GameManager.ClientMgr.NotifyOtherBiaoCheLifeV(sl, pool, objList, biaoCheItem.BiaoCheID, biaoCheItem.CurrentLifeV); } } } } }
private static bool ProcessBiaoCheDead(SocketListener sl, TCPOutPacketPool pool, long nowTicks, BiaoCheItem biaoCheItem) { bool result; if (biaoCheItem.CurrentLifeV > 0) { result = false; } else { long subTicks = nowTicks - biaoCheItem.BiaoCheDeadTicks; if (subTicks < 2000L) { result = false; } else { BiaoCheManager.ProcessDelBiaoChe(sl, pool, biaoCheItem.BiaoCheID); result = true; } } return(result); }
private static bool ProcessBiaoCheOverTime(SocketListener sl, TCPOutPacketPool pool, long nowTicks, BiaoCheItem biaoCheItem) { bool result; if (nowTicks - biaoCheItem.StartTime < (long)Global.MaxYaBiaoTicks) { result = false; } else { BiaoCheManager.ProcessDelBiaoChe(sl, pool, biaoCheItem.BiaoCheID); result = true; } return(result); }
/// <summary> /// 通知其他人被攻击(单攻),并且被伤害(同一个地图才需要通知) /// </summary> /// <param name="client"></param> public static int NotifyInjured(SocketListener sl, TCPOutPacketPool pool, GameClient client, BiaoCheItem enemy, int burst, int injure, double injurePercent, int attackType, bool forceBurst, int addInjure, double attackPercent, int addAttackMin, int addAttackMax, double baseRate = 1.0, int addVlue = 0, int nHitFlyDistance = 0) { int ret = 0; object obj = enemy; { //怪物必须或者才操作 if ((obj as BiaoCheItem).CurrentLifeV > 0) { injure = (obj as BiaoCheItem).CutLifeV; // 技能改造[3/13/2014 LiaoWei] injure = (int)(injure * baseRate + addVlue); // 技能中可配置伤害百分比 injure = (int)(injure * injurePercent); ret = injure; (obj as BiaoCheItem).CurrentLifeV -= (int)injure; //是否需要锁定 (obj as BiaoCheItem).CurrentLifeV = Global.GMax((obj as BiaoCheItem).CurrentLifeV, 0); double enemyLife = (int)(obj as BiaoCheItem).CurrentLifeV; (obj as BiaoCheItem).AttackedRoleID = client.ClientData.RoleID; //判断是否将给敌人的伤害转化成自己的血量增长 GameManager.ClientMgr.SpriteInjure2Blood(sl, pool, client, injure); GameManager.SystemServerEvents.AddEvent(string.Format("镖车减血, Injure={0}, Life={1}", injure, enemyLife), EventLevels.Debug); //判断怪物是否死亡 if ((int)(obj as BiaoCheItem).CurrentLifeV <= 0) { GameManager.SystemServerEvents.AddEvent(string.Format("镖车死亡, roleID={0}", (obj as BiaoCheItem).BiaoCheID), EventLevels.Debug); /// 处理怪物死亡 ProcessBiaoCheDead(sl, pool, client, (obj as BiaoCheItem)); } if ((obj as BiaoCheItem).AttackedRoleID >= 0 && (obj as BiaoCheItem).AttackedRoleID != client.ClientData.RoleID) { GameClient findClient = GameManager.ClientMgr.FindClient((obj as BiaoCheItem).AttackedRoleID); if (null != findClient) { //通知其他在线客户端 GameManager.ClientMgr.NotifySpriteInjured(sl, pool, findClient, findClient.ClientData.MapCode, findClient.ClientData.RoleID, (obj as BiaoCheItem).BiaoCheID, 0, 0, enemyLife, findClient.ClientData.Level, new Point(-1, -1)); //向自己发送敌人受伤的信息 ClientManager.NotifySelfEnemyInjured(sl, pool, findClient, findClient.ClientData.RoleID, enemy.BiaoCheID, 0, 0, enemyLife, 0); } } //通知其他在线客户端 GameManager.ClientMgr.NotifySpriteInjured(sl, pool, client, client.ClientData.MapCode, client.ClientData.RoleID, (obj as BiaoCheItem).BiaoCheID, burst, injure, enemyLife, client.ClientData.Level, new Point(-1, -1)); //向自己发送敌人受伤的信息 ClientManager.NotifySelfEnemyInjured(sl, pool, client, client.ClientData.RoleID, enemy.BiaoCheID, burst, injure, enemyLife, 0); //通知紫名信息(限制当前地图) if (!client.ClientData.DisableChangeRolePurpleName) { GameManager.ClientMgr.ForceChangeRolePurpleName2(sl, pool, client); } } } return(ret); }
/// <summary> /// 通知所有人显示镖车 /// </summary> public static void NotifyOthersShowBiaoChe(SocketListener sl, TCPOutPacketPool pool, BiaoCheItem biaoCheItem) { if (null == biaoCheItem) { return; } GameManager.MapGridMgr.DictGrids[biaoCheItem.MapCode].MoveObject(-1, -1, (int)biaoCheItem.PosX, (int)biaoCheItem.PosY, biaoCheItem); //List<Object> objList = Global.GetAll9Clients(biaoCheItem); //GameManager.ClientMgr.NotifyOthersNewBiaoChe(sl, pool, objList, biaoCheItem); }
/// <summary> /// 处理镖车死亡 /// </summary> /// <param name="sl"></param> /// <param name="pool"></param> /// <param name="client"></param> /// <param name="enemy"></param> private static void ProcessBiaoCheDead(SocketListener sl, TCPOutPacketPool pool, GameClient client, BiaoCheItem biaoCheItem) { if (biaoCheItem.HandledDead) { return; } biaoCheItem.HandledDead = true; biaoCheItem.BiaoCheDeadTicks = TimeUtil.NOW(); GameClient findClient = null; if (biaoCheItem.AttackedRoleID >= 0 && biaoCheItem.AttackedRoleID != client.ClientData.RoleID) { findClient = GameManager.ClientMgr.FindClient(biaoCheItem.AttackedRoleID); if (null != findClient) { client = findClient; } } int yinLiang = 0, experience = 0, yaJin = 0; //获取运镖的银两和经验 Global.GetYaBiaoReward(biaoCheItem.YaBiaoID, out yinLiang, out experience, out yaJin); //获取劫镖后,获取的收入的系数 //int killBiaoCheNum = Global.GetKillBiaoCheNum(client, biaoCheItem); yinLiang /= 2; experience = 0; //增加今日的劫镖次数 int jieBiaoNum = Global.IncTotayJieBiaoNum(client); //int jieBiaoDivNum = (int)Math.Pow(2, jieBiaoNum - 1); //if (jieBiaoDivNum > 0) //{ // yinLiang /= jieBiaoDivNum; // experience /= jieBiaoDivNum; //} //else //{ // yinLiang = 0; // experience = 0; //} //处理角色经验 if (experience > 0) { GameManager.ClientMgr.ProcessRoleExperience(client, experience, true, false); } //奖励用户银两 //异步写数据库,写入银两 if (yinLiang > 0) { //过滤银两奖励 yinLiang = Global.FilterValue(client, yinLiang); GameManager.ClientMgr.AddUserYinLiang(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, yinLiang, "押镖奖励"); GameManager.SystemServerEvents.AddEvent(string.Format("角色获取银两, roleID={0}({1}), Money={2}, newMoney={3}", client.ClientData.RoleID, client.ClientData.RoleName, client.ClientData.YinLiang, yinLiang), EventLevels.Record); } //更新押镖的数据库状态 GameManager.DBCmdMgr.AddDBCmd((int)TCPGameServerCmds.CMD_DB_UPDATEYABIAODATASTATE, string.Format("{0}:{1}", biaoCheItem.OwnerRoleID, 1 ), null, client.ServerId); findClient = GameManager.ClientMgr.FindClient(biaoCheItem.OwnerRoleID); if (null != findClient) { //修改押镖数据 if (null != findClient.ClientData.MyYaBiaoData) { findClient.ClientData.MyYaBiaoData.State = 1; //将新的押镖数据通知客户端 GameManager.ClientMgr.NotifyYaBiaoData(findClient); } } else //对方已经离线或者在其他线 { string gmCmdData = string.Format("-setybstate2 {0} 1", biaoCheItem.OwnerRoleID); //转发GM消息到DBServer GameManager.DBCmdMgr.AddDBCmd((int)TCPGameServerCmds.CMD_SPR_CHAT, string.Format("{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7}:{8}", client.ClientData.RoleID, "", 0, "", 0, gmCmdData, 0, 0, -1), null, GameManager.LocalServerIdForNotImplement); } //镖车被劫杀的提示 Global.BroadcastKillBiaoCheHint(client, biaoCheItem); }
public static void NotifyOthersShowBiaoChe(SocketListener sl, TCPOutPacketPool pool, BiaoCheItem biaoCheItem) { if (null != biaoCheItem) { GameManager.MapGridMgr.DictGrids[biaoCheItem.MapCode].MoveObject(-1, -1, biaoCheItem.PosX, biaoCheItem.PosY, biaoCheItem); } }