// for defining from an existng IBaseUnit public BaseUnit( string name, IBaseUnit otherUnit, decimal multiplier, decimal offset = 0, string?symbol = null) : base(name, otherUnit, multiplier, offset, symbol) { }
/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { IBaseUnit unitsCasted = item.As <IBaseUnit>(); if ((unitsCasted != null)) { this._parent.Units.Add(unitsCasted); } }
/// <summary> /// Removes the given item from the collection /// </summary> /// <returns>True, if the item was removed, otherwise False</returns> /// <param name="item">The item that should be removed</param> public override bool Remove(IModelElement item) { IBaseUnit baseUnitItem = item.As <IBaseUnit>(); if (((baseUnitItem != null) && this._parent.Units.Remove(baseUnitItem))) { return(true); } return(false); }
public static void _update_pl_tracing(IBaseUnit sprite, Tracing trace, int frang, int trang, int cur_clock_tm) { bool can_reach = true; IMapUnit pl = sprite.get_pack_data(); if (trace.trace_tm_left > 0 || cur_clock_tm - sprite.last_trace_target_tm > 500) { } }
/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { if ((this._parent.BaseUnit == null)) { IBaseUnit baseUnitCasted = item.As <IBaseUnit>(); if ((baseUnitCasted != null)) { this._parent.BaseUnit = baseUnitCasted; return; } } }
public IOrderedEnumerable <IMaybeNamed> GetAllDependents(ref IEnumerable <IMaybeNamed> toIgnore) { var res = IUnit.GetAllDependents(this, ref toIgnore).AsEnumerable(); var unitsComposedOfThis = IBaseUnit.GetAllIDerivedUnitsComposedOf(this); res = res.Union(unitsComposedOfThis); foreach (var unit in unitsComposedOfThis.Except(toIgnore)) { res = res.Union(unit.GetAllDependents(ref toIgnore)); } res.ThrowIfSetContains(this); return(res.SortByTypeAndName()); }
public bool AddWorkableUnitToQueue(Type model, string name, Coordinates coordinatesStatio, Coordinates coordinatesWork) { bool result = false; IWorkingUnit workingUnit = Activator.CreateInstance(model) as IWorkingUnit; workingUnit.ParkingPos = coordinatesStatio; workingUnit.WorkingPos = coordinatesWork; Thread th = new Thread(() => { lock (lockObj) { if (QueueFreeSlots == 0 && StorageFreeSlots == 0) { result = false; } else { FactoryQueueElement element = new FactoryQueueElement(model, name, coordinatesStatio, coordinatesWork); Queue.Enqueue(element); Thread.Sleep(TimeSpan.FromSeconds(workingUnit.BuildTime)); QueueTime += TimeSpan.FromSeconds(workingUnit.BuildTime); if (StorageFreeSlots > 0) { Queue.Dequeue(); IBaseUnit baseUnit = (IBaseUnit)workingUnit; baseUnit.Move(coordinatesStatio, coordinatesWork); Storage.Add(Activator.CreateInstance(model) as ITestingUnit); } result = true; } } }); th.Start(); return(result); }
public void die(IBaseUnit killer) { if (this.dying) { return; } this.dying = true; long cur_clock_tm = DateTime.Now.ToBinary(); // 尝试触发死亡ai动作 this._trig_dying_act(cur_clock_tm); // TO DO : player die // 中断打坐 //this.try_stop_recover(); this.respawn_tm = cur_clock_tm + 30000; // 30 秒后安全复活 this.pinfo.isdie = true; pinfo.atking = null; pinfo.moving = null; if (pinfo.states != null) { bool _remark_pl_state = false; if (this.pinfo.states.state_par.Count > 0) { for (var idx = 0; idx < this.pinfo.states.state_par.Count; ++idx) { var val = this.pinfo.states.state_par[idx]; if (val.desc.die_keep == 1) continue; this.pinfo.states.state_par.RemoveAt(idx); --idx; _remark_pl_state = true; } } //pinfo.states.state = 0; //pinfo.states.mov_spd_mul = 1.0; //pinfo.states.atk_spd_mul = 1.0; //pinfo.states.mp2hp = 0; //pinfo.states.dmglnkper = 0; //re_calc_cha_data(); if (_remark_pl_state) Skill._remark_pl_state(this, pinfo); } if (pinfo.jumping != null) { // 跳跃中死亡,落在目标点 pinfo.x = pinfo.jumping.dest_x; pinfo.y = pinfo.jumping.dest_y; if (!this.is_in_lvl) { pinfo.lx = pinfo.x; pinfo.ly = pinfo.y; } pinfo.jumping = null; } if (gmap != null) { if (gmap.blvlmap) { //if (this.gmap.worldsvr.is_lvlmis_lvl()) //{ // this.allow_respawn_tm = sys.clock_time() + 6000; // 侠客行副本中,必须6秒后复活 //} this.gmap.worldsvr.on_ply_die(this); } else { if (gmap.pk_seting != map_pk_setting_type.MPST_PK) {//经验惩罚 } } if (killer != null && killer.get_sprite_type() == map_sprite_type.MstMonster) { if (killer.owner_ply != null) { killer = killer.owner_ply; // 宠物击杀相当于玩家角色击杀 } } if (killer != null && killer.get_sprite_type() == map_sprite_type.MstPlayer) { IMapUnit killer_pl = killer.get_pack_data(); //local pkdp = true; if (!gmap.blvlmap) { // 添加仇敌 //_add_foes(this, killer.pinfo); //计算pk值 //是否为中立地图 if (gmap.pk_seting == map_pk_setting_type.MPST_NORMAL) { if (!this.can_atk_direct()) { //自己为正义玩家 //sys.dumpobj( defend_tm_map ); //sys.trace( sys.SLT_ERR, "killer.pinfo.cid = " + killer.pinfo.cid + "sys.time()" + sys.time() + "\n") int killer_cid = killer_pl.cid; long defend_en_tm = 0; long now_s = DateTime.Now.ToBinary(); defend_tm_map.TryGetValue(killer_cid, out defend_en_tm); if (defend_en_tm > 0) { //自己是正当防卫 则 if (defend_en_tm >= now_s) { //增加对方pk值 int add_val = 1; int pkv = killer_pl.pk_v; if (pkv < 0) {//击杀者 有正义值 则清除 add_val = 1 - pkv; } killer.add_pk_v(add_val); } else { defend_tm_map.Remove(killer_cid); } } } else {//可直接攻击的玩家 if (killer.is_justice()) {//击杀者 为正义玩家 降低PK值 killer.sub_pk_v(1, true); } } } this.check_tsk_attribute(true); } else { // 在副本中 // 增加击杀值 killer_pl.kp++; killer_pl.cur_kp++; this.gmap.worldsvr.on_kp(killer, this); } } // remove atking from atker // TO DO : 增加被锁定列表,死亡后清理被锁定列表中的对象的攻击信息即可 foreach (var val in gmap.map_sprites.Values) { val.on_spr_die(pinfo.iid); } } // 清理助攻列表 if (this.kp_asist_rec) { this.beatk_ply_cids.Clear(); } }
public void on_hurt(IBaseUnit tar_sprite) { //当攻击到别的目标时 触发的被动 // if(!this.has_wing()) return; // foreach (pos,state in pinfo.wingholes.actstates) //{ // local state_conf = get_wing_stat_conf(state.sid); // if (!state_conf) // { // ::send_rpc(sid, 252, { res = game_err_code.CONFIG_ERR}); // return; // } // if (("atk" in state_conf ) && state_conf.atk > 0 ) // { //攻击类型状态技能 // on_mount_st_trig(state, tar_sprite, state_conf, false); // } // } }
public void release_petmon(bool dead = false, bool clearinfo = true) { //if (clearinfo) //{ // this.pinfo.pet_mon.mid = 0; // this.pinfo.pet_mon.fintm = 0; //} if (petmon_inst == null) { return; } if (!dead) { petmon_inst.die(null, false); } petmon_inst.get_pack_data().owner_cid = 0; petmon_inst.owner_ply = null; this.gmap.release_pet_mon(petmon_inst); petmon_inst = null; }
public bool can_atk(IBaseUnit spr) { if (null != this.owner_ply) { return this.owner_ply.can_atk(spr); } if (this.get_sprite_type() == map_sprite_type.MstMonster && null != spr.owner_ply) spr = spr.owner_ply; IMapUnit pl = spr.get_pack_data(); if (pl.lvlsideid > 0) return this.mondata.lvlsideid != pl.lvlsideid; if (this.mondata.lvlsideid == 0 && spr.get_sprite_type() == map_sprite_type.MstMonster) return false; return true; }
public void ondmg(IBaseUnit atker, int dmg) { if (!this.shkilawd) return; if (this.get_sprite_type() == map_sprite_type.MstMonster) return; int cid = atker.get_pack_data().cid; if (this.dmglist.ContainsKey(cid)) this.dmglist[cid] += dmg; else { this.dmglist[cid] = dmg; } this.lastdmgtm = DateTime.Now.ToBinary(); }
public void die(IBaseUnit killer, bool clear_owner = true) { if (dying) return; dying = true; this.mondata.isdie = true; long cur_clock_tm = DateTime.Now.ToBinary(); if (this.mondata.respawn_tm < 3100) this.respawn_tm = 3100 + cur_clock_tm; else this.respawn_tm = this.mondata.respawn_tm + cur_clock_tm; this.die_tm = cur_clock_tm; this.mondata.atking = null; this.mondata.moving = null; if (null != this.mondata.jumping) { this.mondata.x = this.mondata.jumping.dest_x; this.mondata.y = this.mondata.jumping.dest_y; this.mondata.jumping = null; } if (null != this.mondata.patrol) { this.mondata.patrol.idx = 0; this.mondata.patrol.cnt = this.mondata.patrol.init_cnt; } foreach (IBaseUnit bu in this.gmap.map_sprites.Values) { IMapUnit ux = bu.get_pack_data(); if (null != ux.atking) { if (ux.atking.tar_iid == this.iid) ux.atking = null; } bu.on_spr_die(this.iid); } if (null != killer) { if (killer.get_sprite_type() == map_sprite_type.MstMonster) if (null != killer.owner_ply) killer = killer.owner_ply; //ISprite owner = this; //owner.remove_from_hurt_from_iids(this.iid); } this.hatelist.Clear(); this._on_leave_battle(cur_clock_tm); //this.mondata.atking = null; //this.mondata.moving = null; //if (null != this.mondata.jumping) //{ // this.mondata.x = this.mondata.jumping.dest_x; // this.mondata.y = this.mondata.jumping.dest_y; // this.mondata.jumping = null; //} foreach (KeyValuePair<int, IBaseUnit> pair in this.gmap.map_sprites) { IMapUnit unit = pair.Value.get_pack_data(); if (null != unit.atking) { if (unit.atking.tar_iid == this.mondata.iid) unit.atking = null; } } }
public static void calc_cha_data(IBaseUnit sprite, IMapUnit sprite_pl, bool full_hp = false) { }
public static void apply_rang_eff(long cur_clock_tm, IBaseUnit from, IPoint2D center, List<tres_conf> sk_res, rang_conf trang, int sid, int per) { var gmap = from.gmap; var maxi = trang.maxi; if (maxi == 0) maxi = 0x7fffffff; int aff_count = 0; Utility.debug(" ================= apply_rang_eff ================= "); //var test_cost_tm = sys.clock_time(); int cirang = trang.cirang; if (cirang > 0) { // 以center中心、cirang为半径的圆形区域 var pow_range = cirang * cirang; //var inzoneplys = from.get_inz_plys(); foreach (var val in gmap.map_players.Values) { if (val.isdie() || val.isghost()) { continue; } var pl_data = val.get_pack_data(); var dist_x = Math.Abs(pl_data.x - center.x); if (dist_x > cirang) { Utility.debug("pow_range[" + pow_range + "] <= dist_x[" + dist_x + "] center.x[" + center.x + "] , center.y[" + center.y + "] pl_data.x[" + pl_data.x + "] , pl_data.y[" + pl_data.y + "]"); continue; // 不在范围内 } var dist_y = Math.Abs(pl_data.y - center.y); if (dist_y > cirang) { Utility.debug("pow_range[" + pow_range + "] <= dist_y[" + dist_y + "] center.x[" + center.x + "] , center.y[" + center.y + "] pl_data.x[" + pl_data.x + "] , pl_data.y[" + pl_data.y + "]"); continue; // 不在范围内 } var rang1 = dist_x * dist_x + dist_y * dist_y; if (rang1 > pow_range) { Utility.debug("pow_range[" + pow_range + "] <= rang1[" + rang1 + "] center.x[" + center.x + "] , center.y[" + center.y + "] pl_data.x[" + pl_data.x + "] , pl_data.y[" + pl_data.y + "]"); continue; } var affed = false; foreach (var tres in sk_res) { var ret = apply_skill_eff_to(cur_clock_tm, from, val, tres, tres.aff, sid, per); if (ret) { affed = true; } } if (affed) { ++aff_count; if (aff_count >= maxi) { break; } } } if (aff_count < maxi) { //var inzonemons = from.get_inz_mons(); foreach (IBaseUnit val in gmap.map_mons.Values) { if (val.isdie() || val.isghost()) { continue; } var pl_data = val.get_pack_data(); var dist_x = Math.Abs(pl_data.x - center.x); if (dist_x - pl_data.size > cirang) continue; // 不在范围内 var dist_y = Math.Abs(pl_data.y - center.y); if (dist_y - pl_data.size > cirang) continue; // 不在范围内 var rang1 = Math.Sqrt(dist_x * dist_x + dist_y * dist_y); if (rang1 - pl_data.size > cirang) { continue; // 不在范围内 } var affed = false; foreach (var tres in sk_res) { var ret = apply_skill_eff_to(cur_clock_tm, from, val, tres, tres.aff, sid, per); if (ret) { affed = true; } } if (affed) { ++aff_count; if (aff_count >= maxi) { break; } } } } } else if (trang.fan != null) { int fan_angle = trang.fan.angle; int fan_rang = trang.fan.rang; // 以from为中心,center为目标,fan.rang为半径,fan.angle为角度的扇形区域 var frm_pl = from.get_pack_data(); var x1 = center.x - frm_pl.x; var y1 = center.y - frm_pl.y; var rang1 = x1 * x1 + y1 * y1; if (rang1 != 0) { rang1 = Math.Sqrt(rang1); var h_angle = Math.Cos(fan_angle / 360.0 * Math.PI); var maxrange = fan_rang; var pow_maxrange = maxrange * maxrange; //var inzoneplys = from.get_inz_plys(); foreach (var val in gmap.map_players.Values) { if (val.isdie() || val.isghost()) { continue; } var pl_data = val.get_pack_data(); var x2 = pl_data.x - frm_pl.x; if (Math.Abs(x2) >= maxrange) continue; // 不在范围内 var y2 = pl_data.y - frm_pl.y; if (Math.Abs(y2) >= maxrange) continue; // 不在范围内 double rang2 = x2 * x2 + y2 * y2; //sys.trace( sys.SLT_DETAIL, "x2 = " + x2 + " y2 = " + y2 + "\n" ); if (rang2 >= pow_maxrange) { continue; // 不在范围内 } rang2 = Math.Sqrt(rang2); var angleVal = (rang2 != 0) ? (x1 * x2 + y1 * y2) / (rang2 * rang1) : 1; //sys.trace( sys.SLT_DETAIL, "apply_rang_eff rang2 = " + rang2 + "rang1 = " + rang1 + "\n" ); //sys.trace( sys.SLT_DETAIL, "apply_rang_eff angleVal = " + angleVal + "h_angle = " + h_angle + "\n" ); if (angleVal < h_angle) { continue;// 不在范围内 } var new_per = per; if (trang.fan.decay != null && trang.fan.decay.Count > 0) {//衰减 var dist = rang2; foreach (var decay in trang.fan.decay) { if (decay.min <= dist && decay.max > dist) { new_per *= (int)(decay.per / 100.0); break; } } } var affed = false; foreach (var tres in sk_res) { var ret = apply_skill_eff_to(cur_clock_tm, from, val, tres, tres.aff, sid, new_per); if (ret) { affed = true; } } if (affed) { ++aff_count; if (aff_count >= maxi) break; } } if (aff_count < maxi) { //var inzonemons = from.get_inz_mons(); foreach (IBaseUnit val in gmap.map_mons.Values) { if (val.isdie() || val.isghost()) { continue; } var pl_data = val.get_pack_data(); var x2 = pl_data.x - frm_pl.x; if (Math.Abs(x2) - pl_data.size >= maxrange) continue; // 不在范围内 var y2 = pl_data.y - frm_pl.y; if (Math.Abs(y2) - pl_data.size >= maxrange) continue; // 不在范围内 var rang2 = Math.Sqrt(x2 * x2 + y2 * y2); //sys.trace( sys.SLT_DETAIL, "x2 = " + x2 + " y2 = " + y2 + "\n" ); if (rang2 - pl_data.size >= maxrange) { continue; // 不在范围内 } var angleVal = (rang2 != 0) ? (x1 * x2 + y1 * y2) / (rang2 * rang1) : 1; //sys.trace( sys.SLT_DETAIL, "apply_rang_eff rang2 = " + rang2 + "rang1 = " + rang1 + "\n" ); //sys.trace( sys.SLT_DETAIL, "apply_rang_eff angleVal = " + angleVal + "h_angle = " + h_angle + "\n" ); if (angleVal < h_angle) { continue;// 不在范围内 } var new_per = per; if (trang.fan.decay != null && trang.fan.decay.Count > 0) {//衰减 var dist = rang2; foreach (var decay in trang.fan.decay) { if (decay.min <= dist && decay.max > dist) { new_per *= (int)(decay.per / 100.0); break; } } } var affed = false; foreach (var tres in sk_res) { var ret = apply_skill_eff_to(cur_clock_tm, from, val, tres, tres.aff, sid, new_per); if (ret) { affed = true; } } if (affed) { ++aff_count; if (aff_count >= maxi) break; } } } } } else if (trang.ray != null) { // 以from为中心,center为目标,fan.dist为距离,fan.width为宽度的矩形区域 var ray = trang.ray; var frm_pl = from.get_pack_data(); var x1 = center.x - frm_pl.x; var y1 = center.y - frm_pl.y; var rang1 = x1 * x1 + y1 * y1; if (rang1 != 0) { rang1 = Math.Sqrt(rang1); var hwidth = ray.width / 2.0; //var inzoneplys = from.get_inz_plys(); foreach (var val in gmap.map_players.Values) { if (val.isdie() || val.isghost()) { continue; } var pl_data = val.get_pack_data(); var x2 = pl_data.x - frm_pl.x; var y2 = pl_data.y - frm_pl.y; var dotVal = x1 * x2 + y1 * y2; //sys.trace( sys.SLT_DETAIL, " iid = " + pl_data.iid + " dotVal = " + dotVal + "\n" ); if (dotVal < 0) { continue;// 不在范围内 } var projVal = dotVal / rang1; //sys.trace( sys.SLT_DETAIL, " dotVal = " + dotVal + " projVal = " + projVal + "\n" ); if (projVal - pl_data.size > ray.dist) { continue;// 不在范围内 } var vertVal = x2 * x2 + y2 * y2 - projVal * projVal;//小数会产生误差 出现负数的情况 //sys.trace( sys.SLT_DETAIL, "apply_rang_eff vertVal = " + vertVal + " pl_data.size =" + pl_data.size + "\n" ); if (vertVal > 0 && Math.Sqrt(vertVal) > hwidth) { continue;// 不在范围内 } var affed = false; foreach (var tres in sk_res) { var ret = apply_skill_eff_to(cur_clock_tm, from, val, tres, tres.aff, sid, per); if (ret) { affed = true; } } if (affed) { ++aff_count; if (aff_count >= maxi) break; } } if (aff_count < maxi) { //var inzonemons = from.get_inz_mons(); foreach (var val in gmap.map_mons.Values) { if (val.isdie() || val.isghost()) { continue; } var pl_data = val.get_pack_data(); var x2 = pl_data.x - frm_pl.x; var y2 = pl_data.y - frm_pl.y; var dotVal = x1 * x2 + y1 * y2; //sys.trace( sys.SLT_DETAIL, " iid = " + pl_data.iid + " dotVal = " + dotVal + "\n" ); if (dotVal < 0) { continue;// 不在范围内 } var projVal = dotVal / rang1; //sys.trace( sys.SLT_DETAIL, " dotVal = " + dotVal + " projVal = " + projVal + "\n" ); if (projVal - pl_data.size > ray.dist) { continue;// 不在范围内 } var vertVal = x2 * x2 + y2 * y2 - projVal * projVal;//小数会产生误差 出现负数的情况 //sys.trace( sys.SLT_DETAIL, "apply_rang_eff vertVal = " + vertVal + " pl_data.size =" + pl_data.size + "\n" ); if (vertVal > 0 && Math.Sqrt(vertVal) > hwidth) { continue;// 不在范围内 } var affed = false; foreach (var tres in sk_res) { var ret = apply_skill_eff_to(cur_clock_tm, from, val, tres, tres.aff, sid, per); if (ret) { affed = true; } } if (affed) { ++aff_count; if (aff_count >= maxi) break; } } } } } //sys.trace( sys.SLT_DETAIL, " apply_rang_eff tm= " + (sys.clock_time()-test_cost_tm) + " \n" ); }
public void onhate(IBaseUnit atker, int dmg) { // monster特有函数,player不做处理 if (petmon_inst != null) { petmon_inst.onhate(atker, dmg); } }
public bool isaily(IBaseUnit spr) { if (spr.get_sprite_type() == map_sprite_type.MstMonster && spr.owner_ply != null) spr = spr.owner_ply; // 用主人代替宠物检查敌我关系 IMapUnit pl = spr.get_pack_data(); if (pl.iid == this.pinfo.iid) return true; if (pl.lvlsideid != 0 && pinfo.lvlsideid == pl.lvlsideid) return true; if (pl.teamid == 0 || pinfo.teamid == 0) return false; if (pl.teamid == pinfo.teamid) return true; if (pl.clanid == 0 || pinfo.clanid == 0) return false; if (pl.clanid == pinfo.clanid) return true; return false; }
public static int distance2(IBaseUnit a, IBaseUnit b) { IMapUnit ma = a.get_pack_data(); IMapUnit mb = a.get_pack_data(); if (ma == null || mb == null) return 0; return (int)(Math.Pow(ma.x - mb.x, 2) + Math.Pow(ma.y - mb.y, 2)); }
public void on_hurt(IBaseUnit tar_sprite) { }
public static game_err_code check_target_type(IBaseUnit caster, IBaseUnit tar_sprite, int aff, map_pk_setting_type map_pk_seting) { IMapUnit pl = caster.get_pack_data(); IMapUnit tar_pl = tar_sprite.get_pack_data(); if (pl.iid != tar_pl.iid) { // 作用于其他角色 if ((aff & (int)skill_aff_type.SAT_ENERMY) != (int)skill_aff_type.SAT_ENERMY) { if (caster.can_atk(tar_sprite)) return game_err_code.SKIL_INVALIDE_TAREGET;//敌人 // 根据aff判断盟友关系从而确定是否受此状态影响 var isaily = caster.isaily(tar_sprite); if (isaily) { if ((aff & (int)skill_aff_type.SAT_ALLY) != (int)skill_aff_type.SAT_ALLY) return game_err_code.SKIL_INVALIDE_TAREGET; // 不对盟友产生影响 } else {//中立方 if ((aff & (int)skill_aff_type.SAT_MID) != (int)skill_aff_type.SAT_MID) return game_err_code.SKIL_INVALIDE_TAREGET; } } else if (caster.get_sprite_type() == map_sprite_type.MstPlayer) {// 根据地图、个人pk状态决定是否可以释放技能 if (tar_sprite.get_sprite_type() == map_sprite_type.MstPlayer) { if (map_pk_seting == map_pk_setting_type.MPST_PEACE) return game_err_code.CANT_PK_IN_PEACE_MAP; if (pl.in_pczone || tar_pl.in_pczone) return game_err_code.CANT_PK_IN_PEACE_ZONE; if (map_pk_seting == map_pk_setting_type.MPST_NORMAL) { if (!tar_sprite.can_atk_direct()) { //不可攻击的玩家 if (!caster.can_atk(tar_sprite)) return game_err_code.CANT_ATK; } } else { //pk地图 if (!caster.can_atk(tar_sprite)) return game_err_code.CANT_ATK; } } else if (tar_sprite.get_sprite_type() == map_sprite_type.MstMonster) { if (tar_sprite.owner_ply != null) { //战宠 var owner_sprite = tar_sprite.owner_ply; var ower_pl = owner_sprite.get_pack_data(); if (ower_pl.iid == pl.iid) return game_err_code.CANT_ATTACK_SELF_PET; if (map_pk_seting == map_pk_setting_type.MPST_PEACE) return game_err_code.CANT_PK_IN_PEACE_MAP; if (pl.in_pczone || ower_pl.in_pczone) return game_err_code.CANT_PK_IN_PEACE_ZONE; if (map_pk_seting == map_pk_setting_type.MPST_NORMAL) { if (!owner_sprite.can_atk_direct()) { //不可攻击的玩家 if (!caster.can_atk(owner_sprite)) return game_err_code.CANT_ATK; } } else { //pk地图 if (!caster.can_atk(owner_sprite)) return game_err_code.CANT_ATK; } } else { if (!caster.can_atk(tar_sprite)) return game_err_code.CANT_ATK; } } } else { if (!caster.can_atk(tar_sprite)) return game_err_code.CANT_ATK; } } else { // 作用于自己 if ((aff & (int)skill_aff_type.SAT_SELF) != (int)skill_aff_type.SAT_SELF) return game_err_code.SKIL_INVALIDE_TAREGET; // 不对自己产生影响 } return game_err_code.RES_OK; }
public bool onhate(IBaseUnit atker, int hate_value, bool callhatp = true) { if (this.collect_tar > 0) return false; if (this.mondata.revange == 0) return false; if (this.running_tm > 0) return false; if (atker.isdie()) return false; if (atker.get_sprite_type() == map_sprite_type.MstMonster) if (atker.collect_tar > 0) return false; if (!can_atk(atker)) return false; int atker_iid = atker.get_pack_data().iid; if (this.iid == atker_iid) return false; if (this.monconf.ai.hate_add > 0) { hate_value = this.monconf.ai.hate_add; } if (this.hatelist.ContainsKey(atker_iid)) this.hatelist[atker_iid] += hate_value; else { this.hatelist[atker_iid] = hate_value; if (this.monconf.ai.hatp > 0) { long dist2 = this.mondata.defrang * this.mondata.defrang; foreach (KeyValuePair<int, IBaseUnit> pair in this.gmap.map_mons) { var m = pair.Value as Monster; if (m.iid == this.iid) continue; if (m.monconf.ai.hatp <= 0) continue; if (!same_hatp(m)) continue; if (m.hatelist.ContainsKey(atker_iid)) continue; if (Utility.distance2(this, m) < dist2) { m.onhate(atker, hate_value, false); } } } } if (this.mondata.atking == null) { if (this.mondata.patrol != null && this.mondata.patrol.tracing == null) { this.mondata.patrol.movto.trinitx = (int)this.mondata.x; this.mondata.patrol.movto.trinity = (int)this.mondata.y; this.mondata.patrol.movto.tracing = true; } long now = DateTime.Now.ToBinary(); //Dictionary<string,long> this.mondata.atking = new atking() { tar_iid = atker.iid, start_tm = now - this.mondata.atkcdtm, trace_tm_left = 0 }; //TODO broadcast this.broad_cast_zone_msg(12, new NetMsgData()); } return true; }
public static void rmv_state_from_pl_by_att(string att_key, IBaseUnit baseUnit) { }
public bool isaily(IBaseUnit spr) { if (null != this.owner_ply) return this.owner_ply.isaily(spr); if (spr.get_sprite_type() == map_sprite_type.MstMonster && null != spr.owner_ply) { spr = spr.owner_ply; } IMapUnit pl = spr.get_pack_data(); if (pl.lvlsideid > 0) { return pl.lvlsideid == this.mondata.lvlsideid; } if (spr.get_sprite_type() == map_sprite_type.MstMonster) return true; return false; }
public static void apply_rang_eff(long now, IBaseUnit from, Point2D center, List<skill_state_conf> sk_res, skill_conf_trang trang, int percentage) { grid_map gmap = from.gmap; int maxi = trang.maxi; if (maxi <= 0) maxi = int.MaxValue; int aff_count = 0; if (trang.cirang > 0) { long _rang = trang.cirang*trang.cirang; foreach (var m in gmap.map_players.Values) { if(m.isdie() || m.isghost()) continue; long _dist_x = Utility.distance2(m, from); if(_dist_x > _rang) continue; bool affed = false; foreach (skill_state_conf tres in sk_res) affed= apply_skill_eff_to(now, from, m, tres, tres.aff, 100); if (affed) { aff_count++; if(aff_count >= maxi) break; } } if (aff_count < maxi) { foreach (var m in gmap.map_mons.Values) { if(m.isdie() || m.isghost()) continue; if(Utility.distance2(m,from) > _rang) continue; bool affed = false; foreach (skill_state_conf tres in sk_res) affed = apply_skill_eff_to(now, from, m, tres, tres.aff, 100); } } } }
public void on_dmg(IBaseUnit frm_sprite, IBaseUnit tar_sprite, double dmg) { }
public static void rmv_1_stat_from_pl_by_gb(int state, IBaseUnit target) { }
public void call_petmon(int mid, long fintm) { // 创建出战战斗宠物 if (this.gmap == null) { return; } //相同 战宠 已招则取消召唤 if (petmon_inst != null && petmon_inst.get_pack_data().mid == mid) { release_petmon(); return; } release_petmon(false, false); map_mon_conf monconf = new map_mon_conf() { mid = mid, x = 0, y = 0, r_x = 8, r_y = 8, spwan_time = 0 }; petmon_inst = this.gmap.new_pet_mon(this, monconf); if (null == petmon_inst) { return; } this.pet_mon.mid = mid; this.pet_mon.fintm = fintm; IMapUnit mondata = petmon_inst.get_pack_data(); mondata.follow = new follow() { start_tm = Utility.time(), tar_iid = pinfo.iid, trace_tm_left = 0, frang = 78400, trang = 8100, do_ai = true };//280*280 }
public static IBaseUnit_State add_state_to_pl(long now, IBaseUnit target, skill_state_conf sk_res, IBaseUnit from, int per) { }
public void on_be_hurt(IBaseUnit frm_sprite) { //当被攻击时 触发的被动 // if(!this.has_wing()) return; // foreach (pos,state in pinfo.wingholes.actstates) //{ // local state_conf = get_wing_stat_conf(state.sid); // if (!state_conf) // { // ::send_rpc(sid, 252, { res = game_err_code.CONFIG_ERR}); // return; // } // if (("def" in state_conf ) && state_conf.def > 0 ) // { //防御类型状态技能 // on_mount_st_trig(state, frm_sprite, state_conf, true); // } // } }
public static bool apply_skill_eff_to(long now, IBaseUnit from, IBaseUnit target, skill_state_conf sk_res, int aff, int percentage) { if (target.isghost() || target.isdie()) return false; if (target.ignore_dmg()) return false; if (sk_res.rate > 0) { if (new Random().Next(0, 100) > sk_res.rate) return false; } if (target.has_state(pl_state_type.PST_SKILL_AVOID)) return false; if (from.iid != target.iid) { if (!skill_conf.skill_target_type_validation(aff, skill_aff_type.SAT_ENERMY)) { if (from.can_atk(target)) return false; if (from.isaily(target)) { if (!skill_conf.skill_target_type_validation(aff, skill_aff_type.SAT_ALLY)) return false; } else { if (!skill_conf.skill_target_type_validation(aff, skill_aff_type.SAT_MID)) return false; } } else { if (from.Is_Player()) { if (target.Is_Player()) { if (target.get_pack_data().in_pczone || from.get_pack_data().in_pczone) return false; if (!from.can_atk(target)) return false; } else if (target.Is_Monster()) { if (target.owner_ply != null) { if (target.owner_ply.iid == from.iid) return false; if (target.owner_ply.get_pack_data().in_pczone || from.get_pack_data().in_pczone) return false; if (!from.can_atk(target)) return false; } } } else { if (!from.can_atk(target)) return false; } } } else { if(!skill_conf.skill_target_type_validation(aff,skill_aff_type.SAT_SELF)) return false; } if (from.Is_Player()) { if(target.can_atk(from)) target.atk_by(from); } if (sk_res.nodmg == 0) { //TODO do damage } if (sk_res.rmv_stat > 0) rmv_stat_from_pl_by_gb(sk_res.rmv_stat,target); if(sk_res.rmv_1_stat >0) rmv_1_stat_from_pl_by_gb(sk_res.rmv_1_stat,target); if (sk_res.tar_state > 0) { IBaseUnit_State state = add_state_to_pl(now, target, sk_res, from, 100); } if (sk_res.force_move_dir != -1) { int dir = sk_res.force_move_dir; if (sk_res.force_move_dir == 2) dir = new Random().Next(0, 2); int delta_x = target.x - from.x; int delta_y = target.y - from.y; if (delta_x != 0 || delta_y != 0) { Point2D vec=new Point2D(delta_x,delta_y); vec = Utility.normalize_vec2(vec); delta_x = (int)(sk_res.force_move_rang*vec.x); delta_y = (int) (sk_res.force_move_rang*vec.y); if (sk_res.force_move_dir == 0) { target.x += delta_x; target.y += delta_y; } else { target.x -= delta_x; target.y -= delta_y; } } target.get_pack_data().moving = null; target.get_pack_data().casting = null; target.get_pack_data().last_mvpts = null; } return true; }
public void atk_by(IBaseUnit atker) { // attack back // TO DO : be attack }
public static void update_pl_state(long now, IBaseUnit sprite) { }
public void ondmg(IBaseUnit atker, int dmg) { int atker_cid = atker.get_pack_data().cid; long now_s = DateTime.Now.ToBinary(); // 被攻击 if (this.kp_asist_rec) { // 需要记录助攻 if (atker.get_sprite_type() == map_sprite_type.MstMonster) { return; } this.beatk_ply_cids[atker_cid] = now_s; // 记录攻击者cid this.lastdmgtm = now_s; // 记录最后一次受伤害时间 } if (gmap.pk_seting == map_pk_setting_type.MPST_NORMAL) { if (atker.get_sprite_type() == map_sprite_type.MstPlayer) { if (atker_cid != pinfo.cid && !this.can_atk_direct()) { if (!atker.defend_tm_map.ContainsKey(pinfo.cid)) { //是否被正当防御 //是否第一次记录 defend_tm_map[atker_cid] = now_s + 10000; } } } } }
public void atk_by(IBaseUnit atker) { this.onhate(atker, 1); }
public bool can_atk(IBaseUnit spr) { if (spr.get_sprite_type() == map_sprite_type.MstMonster && spr.owner_ply != null) spr = spr.owner_ply; // 用主人代替宠物检查敌我关系 IMapUnit pl = spr.get_pack_data(); if (pl.iid == this.pinfo.iid) return false; //if (spr.get_sprite_type() == map_sprite_type.MstPlayer && pl.level < game_conf.pk_safe_lvl) //{ // return false; //} if (pl.lvlsideid != 0) { if (pinfo.lvlsideid != pl.lvlsideid) return true; if ((gmap != null && !gmap.ignore_side) || spr.get_sprite_type() == map_sprite_type.MstMonster) return false; } bool cannt_pk = false; switch (pinfo.pk_state) { case pk_state_type.PKST_PEACE: cannt_pk = spr.get_sprite_type() == map_sprite_type.MstPlayer; break; case pk_state_type.PKST_PK_ALL: cannt_pk = false; break; case pk_state_type.PKST_PK_TEAM: if (pl.teamid == 0 || pinfo.teamid == 0) cannt_pk = false; else cannt_pk = pl.teamid == pinfo.teamid; break; case pk_state_type.PKST_PK_CLAN: if (pl.clanid == 0 || pinfo.clanid == 0) cannt_pk = false; else cannt_pk = pl.clanid == pinfo.clanid; break; } return !cannt_pk; }
public void on_be_hurt(IBaseUnit frm_sprite) { }