Exemple #1
0
 public void DeleteMapUnit(IMapUnit unit)
 {
     foreach (var pos in unitPositionsMap[unit])
     {
         SetMapUnit(pos, null);
     }
     unitPositionsMap.Remove(unit);
 }
Exemple #2
0
 public void InsertMapUnit(IMapUnit unit)
 {
     Debug.Assert(AreaEmpty(unit.GetPositionsInt()));
     if (unitPositionsMap == null)
     {
         unitPositionsMap = new Dictionary <IMapUnit, List <Vector2Int> >();
     }
     unitPositionsMap.Add(unit, new List <Vector2Int>());
     foreach (var pos in unit.GetPositionsInt())
     {
         SetMapUnit(pos, unit);
         unitPositionsMap[unit].Add(pos);
     }
 }
Exemple #3
0
    public bool _is_pos_in_mvpath(int x, int y, IMapUnit pl, int dist_allow)
    {
        // 判断当前位置
        //Utility.trace_info("_is_pos_in_mvpath x["+x+"] y["+y+"]\n");

        double dist_x = x - pl.x;
        double dist_y = y - pl.y;

        //Utility.trace_info("pl x["+pl.x+"] y["+pl.y+"], dist_x["+dist_x+"] dist_y["+dist_y+"] \n");
        if (dist_allow * dist_allow >= dist_x * dist_x + dist_y * dist_y)
        {
            //Utility.trace_info("cur pos varified\n");
            return true;
        }

        var max_verify_pt = 20; // 最多20个验证点,共20*game_const.map_grid_pixel=640 或 45*20=900 的距离范围
        var verify_cnt = 0;

        if (pl.moving != null)
        {
            if (pl.moving.ppts != null)
            {
                //Utility.trace_info("pl.moving.ppts len["+pl.moving.ppts.Count+"] \n");

                verify_cnt = 0;
                var dist_allow_pow = 1024;       // 1格范围之内 32*game_const.map_grid_pixel
                for (var idx = pl.moving.ppts.Count - 1; idx >= 0; --idx)
                {
                    var pt = pl.moving.ppts[idx];

                    dist_x = x - (pt.x * game_const.map_grid_pixel + 16);
                    dist_y = y - (pt.y * game_const.map_grid_pixel + 16);

                    //Utility.trace_info("ppts pt idx["+idx+"] x["+pt.x+"] y["+pt.y+"], dist_x["+dist_x+"] dist_y["+dist_y+"] \n");

                    if (dist_allow_pow >= dist_x * dist_x + dist_y * dist_y)
                    {
                        //Utility.trace_info("moving ppts idx["+idx+"] varified\n");
                        return true;
                    }

                    ++verify_cnt;
                    if (verify_cnt >= max_verify_pt)
                    {
                        //Utility.trace_info("moving ppts idx["+idx+"] varify failed\n");
                        return false;
                    }
                }
            }
            else
            {
                //方向移动 以当前点为准
            }

            return false;
        }

        return false;
    }
Exemple #4
0
    public void update_teleping(IBaseUnit caster, IMapUnit pl, long cur_clock_tm)
    {
        if (pl.teleping == null)
        {
            return;
        }

        if (pl.teleping.end_tm > cur_clock_tm)
        {
            return;
        }

        pl.x = pl.teleping.dest_x;
        pl.y = pl.teleping.dest_y;

        //Utility.trace_info("pl.x["+pl.x+"] pl.y["+pl.y+"]\n");
        if (caster.get_sprite_type() == map_sprite_type.MstPlayer && !caster.is_in_lvl)
        {
            pl.lx = pl.x;
            pl.ly = pl.y;
        }

        pl.teleping = null;
    }
Exemple #5
0
 public void UpdateMapUnit(IMapUnit unit)
 {
     DeleteMapUnit(unit);
     Debug.Assert(AreaEmpty(unit.GetPositionsInt()));
     InsertMapUnit(unit);
 }
Exemple #6
0
        public static void calc_cha_data(IBaseUnit sprite, IMapUnit sprite_pl, bool full_hp = false)
        {

        }
Exemple #7
0
        public static long get_pl_state_end_tm(int state_val, IMapUnit pl)
        {
            if (pl.states == null)
                return 0;

            if ((pl.states.state & state_val) != state_val)
            {
                return 0;
            }

            long end_tm = 0;

            foreach (var val in pl.states.state_par)
            {
                var i = 0;
                var desc_states = val.desc.s_states;
                for (; i < desc_states.Count; ++i)
                {
                    if ((desc_states[i].tp & state_val) != state_val)
                        continue;

                    if (val.end_tm > end_tm)
                    {
                        end_tm = val.end_tm;
                    }
                }
            }

            return end_tm;
        }
Exemple #8
0
        public static bool has_pl_state(int state_val, IMapUnit pl)
        {
            if (pl.states == null)
                return false;

            if ((pl.states.state & state_val) != state_val)
            {
                return false;
            }

            return true;
        }
Exemple #9
0
        public static void _remark_pl_state(IBaseUnit sprite, IMapUnit pl, bool recalc_att = true)
        {
            if (pl.states == null)
                return;

            if (pl.states.state_par.Count <= 0)
            {
                // 重新计算角色属性
                if (recalc_att)
                {
                    sprite.re_calc_cha_data();
                }

                pl.states = null;
                return;
            }

            pl.states.state = 0;
            pl.states.mov_spd_mul = 1.0;
            pl.states.atk_spd_mul = 1.0;
            pl.states.mp2hp = 0;
            pl.states.dmglnkper = 0;

            //var invisible = 0;

            foreach (var val in pl.states.state_par)
            {
                var i = 0;
                var mp2hp = 0;
                //        if (("attadj" in val) && ("mp2hp" in val.attadj) )
                //{
                //            mp2hp = val.attadj.mp2hp;
                //        }
                //for (; i < val.desc.s_states.len(); ++i)
                //{
                //    pl.states.state = (pl.states.state | val.desc.s_states[i].tp);

                //    //if((val.desc.s_states[i].tp&pl_state_type.PST_MOVE_SPEED_MUL)==pl_state_type.PST_MOVE_SPEED_MUL)
                //    //{
                //    //    pl.states.mov_spd_mul *= val.desc.s_states[i].par.tofloat() * val.par / 100000.0;
                //    //}

                //    //if((val.desc.s_states[i].tp&pl_state_type.PST_ATK_SPEED_MUL)==pl_state_type.PST_ATK_SPEED_MUL)
                //    //{
                //    //    pl.states.atk_spd_mul *= val.desc.s_states[i].par.tofloat() * val.par / 100000.0;
                //    //}

                //    if ((val.desc.s_states[i].tp & pl_state_type.PST_MP2HP) == pl_state_type.PST_MP2HP)
                //    {
                //        if (mp2hp > 0)
                //        {
                //            pl.states.mp2hp += mp2hp;
                //        }
                //        else
                //        {
                //            pl.states.mp2hp += (val.desc.s_states[i].par * val.par / 1000);
                //        }
                //    }
                //    if ((val.desc.s_states[i].tp & pl_state_type.PST_DMGLNK_M) == pl_state_type.PST_DMGLNK_M)
                //    {
                //        pl.states.dmglnkper += (val.desc.s_states[i].par * val.par / 1000);
                //    }

                //    // TO DO : speed add att
                //}

                //if("att" in val.desc)
                //{
                //    if("invisible" in val.desc.att)
                //    {
                //        // 隐身状态
                //        if(val.desc.att.invisible > invisible)
                //        {
                //            invisible = val.desc.att.invisible;
                //        }
                //    }

                //    if(!recalc_att)
                //    {
                //        foreach(key,att in val.desc.att)
                //        {
                //            if(key!="invisible") 
                //            {
                //                // 有需计算属性
                //                recalc_att = true;
                //                break;
                //            }
                //        }
                //    }
                //}
            }

            //if(recalc_att)
            //{
            // 有att调整字段,需要重新计算角色属性
            sprite.re_calc_cha_data();
            //}

            //sprite.visible_change(invisible);
        }
Exemple #10
0
    public static bool is_pt_pos_in_range(IMapUnit p1, IMapUnit p2, int range)
    {
        var distx = (p2.x / game_const.map_grid_pixel) - (p1.x / game_const.map_grid_pixel);
        var disty = (p2.y / game_const.map_grid_pixel) - (p1.y / game_const.map_grid_pixel);

        var dist = Math.Sqrt(distx * distx + disty * disty);

        return dist <= range;
    }
Exemple #11
0
        public void update_skill_casting(IBaseUnit sprite, IMapUnit mapUnit, long now)
        {

        }
Exemple #12
0
        public void update_teleping(IBaseUnit sprite, IMapUnit mapUnit, long now)
        {

        }
Exemple #13
0
 public void SetMapUnit(Vector2Int position, IMapUnit mapUnit)
 {
     SetMapUnit(position.x, position.y, mapUnit);
 }
Exemple #14
0
 public void SetMapUnit(int x, int y, IMapUnit mapUnit)
 {
     data[x][y] = mapUnit;
 }
Exemple #15
0
 public static void _hold_pl_atk(IMapUnit pl, long cd_tm, long cur_clock_tm)
 {
     if (cur_clock_tm - pl.atking.start_tm > cd_tm)
     {
         pl.atking.start_tm = cur_clock_tm - cd_tm;
     }
 }
Exemple #16
0
        public static void rmv_state_from_pl_by_att(string att_key, IBaseUnit sprite, IMapUnit pl)
        {
            if (pl.states == null)
                return;

            var removed_ids = new List<int>();
            for (var idx = 0; idx < pl.states.state_par.Count; ++idx)
            {
                var val = pl.states.state_par[idx];
                //if (val.desc.att != null && val.desc.att.ContainsKey(att_key))
                //{
                //    pl.states.state_par.RemoveAt(idx);
                //    --idx;
                //    removed_ids.push(val.desc.id);
                //}
            }

            if (removed_ids.Count > 0)
            {
                _remark_pl_state(sprite, pl);

                // broadcast rmv_state msg
                //sprite.broad_cast_zone_msg_and_self(31, {iid=pl.iid, ids=removed_ids    });
            }
        }
Exemple #17
0
    public static double pl_absorb_dmg(IBaseUnit sprite, IMapUnit pl, double dmg)
    {
        if (pl.states == null)
            return dmg;


        List<int> remove_stateids = new List<int>();

        for (var idx = 0; idx < pl.states.state_par.Count; ++idx)
        {
            var val = pl.states.state_par[idx];

            if (val.desc.absorbdmg != null)
            {
                //Utility.trace_info("dmg before ["+dmg+"]\n");

                var per = (val.desc.absorbdmg.per / 10);
                if (per > 100) per = 100;

                var absorbdmg = (dmg * per / 100);

                //Utility.trace_info("per ["+per+"]\n");
                //Utility.trace_info("absorbdmg ["+absorbdmg+"]\n");
                //Utility.trace_info("val.maxdmg ["+val.maxdmg+"]\n");

                if (absorbdmg + val.absorbed > val.maxdmg)
                {
                    absorbdmg = val.maxdmg - val.absorbed;
                }

                dmg -= absorbdmg;
                val.absorbed += (int)absorbdmg;

                //Utility.trace_info("dmg after ["+dmg+"] aborbdmg["+absorbdmg+"] \n");

                if (val.absorbed >= val.maxdmg)
                {
                    // 移除吸收伤害状态
                    pl.states.state_par.RemoveAt(idx);
                    --idx;
                    remove_stateids.push(val.desc.id);
                }

                if (dmg <= 0)
                {
                    dmg = 0;
                    break;
                }
            }
        }


        if (remove_stateids.Count > 0)
        {
            // broadcast rmv_state msg
            //    sprite.broad_cast_zone_msg_and_self(31, {
            //        iid = pl.iid, ids = remove_stateids
            //});

            Skill._remark_pl_state(sprite, pl);
        }

        return dmg;
    }
Exemple #18
0
        public static void rmv_1stat_from_pl_by_gb(int rmv_state_gb, IBaseUnit sprite, IMapUnit pl)
        {
            if (pl.states == null || pl.states.state_par.Count <= 0)
                return;

            bool removed = false;
            for (var idx = 0; idx < pl.states.state_par.Count; ++idx)
            {
                var val = pl.states.state_par[idx];
                if (val.desc.gb == rmv_state_gb)
                {
                    pl.states.state_par.RemoveAt(idx);
                    --idx;
                    //removed_ids.push(val.desc.id);
                    removed = true;
                    break;
                }
            }

            //if (removed_ids.len() > 0)
            if (removed)
            {
                _remark_pl_state(sprite, pl);

                // broadcast rmv_state msg
                //sprite.broad_cast_zone_msg_and_self(31, { iid = pl.iid, ids = removed_ids});
            }
        }
Exemple #19
0
    public static double pl_hpdmg_2_mpdmg(IBaseUnit sprite, IMapUnit pl, double dmg)
    {
        if (pl.states == null)
            return dmg;

        if (pl.states.mp2hp > 0)
        {
            //每次受到伤害时角色魔法值减少最大魔法值*2%
            var mp_cost = (pl.max_mp * 0.02);

            if (mp_cost <= pl.mp)
            {
                var mp_dmg = (dmg * pl.states.mp2hp / 100);
                if (mp_dmg > 0)
                {
                    dmg -= mp_dmg;

                    if (dmg < 0) dmg = 0;

                    pl.mp -= (int)mp_cost;
                    if (pl.mp < 0) pl.mp = 0;

                    // send mpchange msg
                    //        if ("sid" in pl) 
                    //{
                    //    ::send_rpc(pl.sid, 32, { mpadd = -mp_cost});
                    //        }
                }
            }
        }

        return dmg;
    }
Exemple #20
0
        public static bool has_pl_state_bystid(int stid, IMapUnit pl)
        {
            if (pl.states == null)
                return false;

            foreach (var val in pl.states.state_par)
            {
                if (val.id == stid)
                {
                    return true;
                }
            }
            return false;
        }
Exemple #21
0
    public static void pl_dmg_link(IBaseUnit frm_sprite, IMapUnit frm_pl, double dmg)
    {
        if (frm_pl.states == null)
            return;

        if (frm_pl.states.dmglnkper <= 0)
            return;

        if (frm_sprite.gmap == null)
            return;

        // 有伤害链接
        var share_dmg = (dmg * (frm_pl.states.dmglnkper / 1000.0));

        // 遍历并传递伤害
        foreach (var sprite in frm_sprite.gmap.map_sprites.Values)
        {
            if (!sprite.has_state(pl_state_type.PST_DMGLNK_S))
                continue;

            if (sprite.isdie())
                continue;

            var pl = sprite.get_pack_data();
            if (pl.iid == frm_pl.iid)
                continue;

            // 吸收伤害
            share_dmg = pl_absorb_dmg(sprite, pl, share_dmg);
            // 魔法抵扣生命
            share_dmg = pl_hpdmg_2_mpdmg(sprite, pl, share_dmg);

            pl.hp -= (int)share_dmg;
            if (pl.hp < 0) pl.hp = 0;

            sprite.onhate(frm_sprite, share_dmg);
            sprite.ondmg(frm_sprite, share_dmg);

            // broadcast hpchange msg
            //sprite.broad_cast_zone_msg_and_self(26, { iid = pl.iid, hpchange ={ hpadd = -share_dmg, die = (pl.hp <= 0), frm_iid = frm_pl.iid} });

            //        if ("cid" in pl)
            //{
            //            var tid = team.get_ply_teamid(pl.cid);
            //            if (tid > 0)
            //            {
            //                // 在队伍中,发送队友属性变化消息
            //                team_bcast_rpc_except(tid, 138, { cid = pl.cid, hp = pl.hp}, pl.sid);
            //            }
            //        }

            if (pl.hp <= 0)
            {
                // 被弹死了
                sprite.die(frm_sprite);
            }
        }
    }
Exemple #22
0
        public static int get_pl_state_par(int state_val, IMapUnit pl)
        {
            if (pl.states == null)
                return 0;

            if ((pl.states.state & state_val) != state_val)
            {
                return 0;
            }

            foreach (var val in pl.states.state_par)
            {
                var i = 0;
                var desc_states = val.desc.s_states;
                for (; i < desc_states.Count; ++i)
                {
                    if ((desc_states[i].tp & state_val) != state_val)
                    {
                        continue;
                    }

                    // TO DO : 考虑多个效果叠加情况
                    // 暂时只取头一个值返回

                    return desc_states[i].par * val.par / 100000;
                }
            }

            return 0;
        }
Exemple #23
0
    public void update_skill_holding(IBaseUnit caster, IMapUnit pl, long cur_clock_tm)
    {
        if (pl.holding == null)
            return;

        var holding = pl.holding;
        if (cur_clock_tm > 0 && cur_clock_tm < holding.end_tm)
        {
            return;
        }

        var senderr = caster.get_sprite_type() == map_sprite_type.MstPlayer;
        switch (holding.tar_tp)
        {
            case (int)skill_type.ST_SELF:
                this.do_cast_self_skill(caster, holding.rpc, false, senderr);
                break;
            case (int)skill_type.ST_TARGET:
                this.do_cast_target_skill(caster, holding.rpc, false, senderr);
                break;
            case (int)skill_type.ST_GROUND:
                this.do_cast_ground_skill(caster, holding.rpc, false, senderr);
                break;
        }
    }
Exemple #24
0
        public static Point2D valpoint_on_line(IMapUnit frm_mapUnit, IPoint2D to_pos, int max_rang, int sublen = 0)
        {
            Point2D frm_pos = new Point2D(frm_mapUnit.x, frm_mapUnit.y);

            return valpoint_on_line(frm_pos, to_pos, max_rang, sublen);
        }
Exemple #25
0
    public void update_jumping(IBaseUnit caster, IMapUnit pl, long cur_clock_tm)
    {
        if (pl.jumping == null)
            return;

        var jumping = pl.jumping;

        if (jumping.end_tm > cur_clock_tm)
        {
            long jumping_tm = cur_clock_tm - jumping.start_tm;
            pl.x += ((jumping.dest_x - pl.x) * jumping_tm / jumping.during_tm);
            pl.y += ((jumping.dest_y - pl.y) * jumping_tm / jumping.during_tm);

            //Utility.trace_info("pl.x["+pl.x+"] pl.y["+pl.y+"]\n");

            if (caster.get_sprite_type() == map_sprite_type.MstPlayer && !caster.is_in_lvl)
            {
                pl.lx = pl.x;
                pl.ly = pl.y;
            }

            return;
        }

        pl.x = jumping.dest_x;
        pl.y = jumping.dest_y;

        if (caster.get_sprite_type() == map_sprite_type.MstPlayer && !caster.is_in_lvl)
        {
            pl.lx = pl.x;
            pl.ly = pl.y;
        }

        int skill_id = jumping.rpc["sid"]._int32;

        if (jumping.jump.tres == null)
            return;

        if (jumping.jump.rang != null)
        {
            Skill.apply_rang_eff(cur_clock_tm, caster, caster.get_pack_data(), jumping.jump.tres, jumping.jump.rang, skill_id, jumping.percent);
        }
        else
        {
            IBaseUnit tar_sprite = caster.gmap.get_sprite_by_iid(pl.jumping.tar_iid);
            if (tar_sprite != null)
            {
                var tar_pl = tar_sprite.get_pack_data();

                var dist_x = tar_pl.x - pl.x;
                var dist_y = tar_pl.y - pl.y;

                if (dist_x * dist_x + dist_y * dist_y < 100 * 100)
                {
                    // 在范围内
                    foreach (var tres in jumping.jump.tres)
                        Skill.apply_skill_eff_to(cur_clock_tm, caster, tar_sprite, tres, tres.aff, skill_id, pl.jumping.percent);
                }
            }

        }
    }