Example #1
0
    public void _trig_res(trigger_conf trconf, IBaseUnit trig_spr, List<int> to_add_trgconf, List<int> to_rmv_tmtrgids,
        List<int> to_rmv_areatrgids, List<int> to_rmv_kmtrgids, List<int> to_rmv_uitmtrgids,
        List<int> to_rmv_mistrgids, List<int> to_rmv_othertrgids)
    {
        //sys.trace(sys.SLT_DETAIL, "map["+this.mapid+"] _trig_res ["+trconf.id+"]\n");

        // 触发触发器
        if (trconf.rate > 0)
        {
            int judg = Utility.random(0, 100);
            //sys.trace(sys.SLT_DETAIL, "judg ["+judg+"] trig_res\n");
            if (judg > trconf.rate)
            {
                // 触发几率未命中,不产生效果
                Utility.trace_info("trigger miss trig_res\n");
                return;
            }
        }

        //if ("mod_monatt" in trconf )
        //{
        //    local mod_monatt_conf = trconf.mod_monatt[0];
        //    if ("matt" in mod_monatt_conf)
        //    {
        //        foreach (modatt in mod_monatt_conf.matt)
        //        {
        //            local adjust_att = { };
        //            if ("spwan_time" in modatt )
        //            {
        //                adjust_att.respawn_tm < -modatt.spwan_time;
        //            }
        //            if (adjust_att.len() > 0)
        //            {
        //                foreach (mon in this.map_mons)
        //                {
        //                    if (mon.mondata.mid == modatt.mid)
        //                    {
        //                        foreach (key, val in adjust_att )
        //                        {
        //                            mon.mondata[key] = val;
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //    }
        //}

        if (trconf.addmon != null)
        {
            // 新增怪物
            var added_mon = this.add_init(trconf.addmon.map_mon);

            if (this.blvlmap && added_mon.Count > 0)
            {
                // 副本地图,根据难度调整怪物等级
                worldsvr._on_triger_addmons(added_mon);
            }
        }

        // 根据callmon触发结果新增添加或复活boss触发结果功能,若新增的话,新增的怪物是死的
        if (trconf.callmon != null)
        {
            // 召唤怪物
            //sys.trace(sys.SLT_DETAIL, "map["+this.mapid+"] callmon ["+trconf.id+"]\n");

            long cur_tm_s = Utility.time();
            //local /*call_mon*/ = [];
            var call_mon_conf = trconf.callmon;
            if (call_mon_conf.map_mon.Count > 0)
            {
                //local m;
                List<IBaseUnit> new_added_mons = new List<IBaseUnit>();
                foreach (var m_conf in call_mon_conf.map_mon)
                {
                    int mon_cnt = 0;
                    IBaseUnit mon = null;
                    foreach (var val in this.map_mons.Values)
                    {
                        IMapUnit mondata = val.get_pack_data();
                        if (mondata.mid == m_conf.mid && mondata.isdie)
                        {
                            mon = val;
                            break;
                        }
                    }
                    if (mon == null)
                    {
                        // 创建
                        //sys.trace(sys.SLT_DETAIL, "callmon["+m.mid+"], create\n");

                        bool bcrt = true;
                        if (this.callmon_added.ContainsKey(m_conf.mid))
                        {
                            if (this.callmon_added[m_conf.mid] >= call_mon_conf.mcnt.cnt)
                            {
                                bcrt = false; // 达到最大数量,不能创建
                            }
                        }

                        if (bcrt)
                        {
                            // 可以创建
                            mon = this.create_monster_byconf(m_conf);
                            if (mon == null)
                            {
                                Utility.trace_err("Err: in map [" + this.mapid + "] callmon mid [" + m_conf.mid + "] create error!\n");
                                return;
                            }

                            IMapUnit mondata = mon.get_pack_data();

                            mon.gmap = this;
                            mon.on_pos_change(mondata.x, mondata.y);

                            this.map_mons[mondata.iid] = mon;
                            this.map_sprites[mondata.iid] = mon;

                            List<IBaseUnit> list = null;
                            if (!this.map_mon_bymid.TryGetValue(mondata.mid, out list))
                            {
                                list = new List<IBaseUnit>();
                                this.map_mon_bymid.Add(mondata.mid, list);
                            }

                            list.Add(mon);

                            //mon.set_add_conf(m);

                            new_added_mons.push(mon);

                            if (this.callmon_added.ContainsKey(mondata.mid))
                                this.callmon_added[mondata.mid]++;
                            else
                                this.callmon_added[mondata.mid] = 1;
                        }
                    }
                    else
                    {
                        // 死亡则复活
                        if (mon.get_pack_data().isdie)
                        {
                            //sys.trace(sys.SLT_DETAIL, "callmon["+mon.mondata.mid+"], respawn\n");
                            mon.respawn(100, true);
                        }
                        else
                        {
                            //sys.trace(sys.SLT_DETAIL, "callmon["+mon.mondata.mid+"], nothing\n");
                        }
                    }

                    //if (("clanbcast" in m) && (m.clanbcast == 1))
                    //{
                    //    // 需要在全帮派广播怪物召唤消息
                    //    if (trig_spr && (trig_spr.get_sprite_type() == map_sprite_type.MST_PLAYER) && ("clanid" in trig_spr.pinfo))
                    //    {
                    //        // broad cast clan_msg msg
                    //        _broad_cast_clan_msg(trig_spr.pinfo.clanid, 226, { tp = 5, callmid = m.mid, cid = trig_spr.pinfo.cid, name = trig_spr.pinfo.name}, clan_c_tp.CCT_NONE);
                    //    }
                    //}
                }

                if (this.blvlmap && new_added_mons.Count > 0)
                {
                    // 副本地图,根据难度调整怪物等级
                    worldsvr._on_triger_addmons(new_added_mons);
                }
            }
            //else
            //{
            //    //sys.trace(sys.SLT_ERR, "map["+this.mapid+"] callmon ["+trconf.id+"] call_mon_conf without m\n");
            //}
        }

        //if (this.blvlmap && ("call_city_mon" in trconf) )
        //{
        //    if (worldsvr.clter_conf && worldsvr.clter_conf.tp == clan_teritory_type.CTT_WAR_TERRITORY)
        //    {
        //        local clterid = worldsvr.clter_conf.id;
        //        local call_city_mon_conf = trconf.call_city_mon[0];

        //        local glbdata_mgr = global_data_mgrs.glbdata;
        //        glbdata_mgr.lock_data(db_glbdata_datatype.DBGDT_CLAN_TER, server_const.GLOBAL_DATA_LOCK_TM); // 锁定数据对象,注意,所有跳出函数代码分支必须要有unlock
        //        local gld_clanter_data = _get_clanter_data();
        //        if (gld_clanter_data)
        //        {
        //            local glb_clanter_info = gld_clanter_data.get_data();
        //            if (clterid in glb_clanter_info.data )
        //            {
        //                local clanter_info = glb_clanter_info.data[clterid];
        //                if (clanter_info && !clanter_info.onwar && clanter_info.clanid > 0 &&
        //                    ("stastic_cost" in clanter_info) && ("cost_callmon" in clanter_info.stastic_cost) )
        //                {
        //                    //sys.dumpobj( clanter_info.cost );     
        //                    local cost_callmon_data = clanter_info.stastic_cost.cost_callmon;
        //                    if (call_city_mon_conf.cost_tp == "yb")
        //                    {
        //                        if (cost_callmon_data.yb > call_city_mon_conf.min_cost)
        //                        {
        //                            local call_mon_cost = this.call_cost_monster(call_city_mon_conf, call_city_mon_conf.cost_tp, cost_callmon_data.yb);
        //                            if (call_mon_cost > 0)
        //                            {
        //                                cost_callmon_data.yb -= call_mon_cost;
        //                                //sys.trace(sys.SLT_DETAIL, "call_city_mon call_mon_cost yb=["+call_mon_cost+"]\n");    
        //                                gld_clanter_data.mod_data(glb_clanter_info);
        //                                gld_clanter_data.db_update();
        //                            }
        //                        }
        //                    }
        //                    else if (call_city_mon_conf.cost_tp == "gold")
        //                    {
        //                        if (cost_callmon_data.gld > call_city_mon_conf.min_cost)
        //                        {
        //                            local call_mon_cost = this.call_cost_monster(call_city_mon_conf, call_city_mon_conf.cost_tp, can_use_gold);
        //                            if (call_mon_cost > 0)
        //                            {
        //                                cost_callmon_data.gld -= call_mon_cost;
        //                                //sys.trace(sys.SLT_DETAIL, "call_city_mon call_mon_cost gld=["+call_mon_cost+"]\n");  
        //                                gld_clanter_data.mod_data(glb_clanter_info);
        //                                gld_clanter_data.db_update();
        //                            }
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //        glbdata_mgr.unlock_data(db_glbdata_datatype.DBGDT_CLAN_TER);  // 解锁                   
        //    }
        //}

        //if ("addbzone" in trconf )
        //{
        //    // 新增动态障碍
        //    foreach (addb in trconf.addbzone)
        //    {
        //        this.add_bzone(addb.id, addb.x, addb.y, addb.w, addb.h);
        //    }
        //}

        //if ("rmvbzone" in trconf )
        //{
        //    // 删除动态障碍
        //    foreach (rmvb in trconf.rmvbzone)
        //    {
        //        this.rmv_bzone(rmvb.id);
        //    }
        //}

        if (!string.IsNullOrEmpty(trconf.addtriger))
        {
            // 新增触发器
            foreach (var tx in trconf.addtriger.Split(','))
            {
                int tid = 0;
                int.TryParse(tx, out tid);
                if (tid > 0 && this.trigger_conf.ContainsKey(tid))
                {
                    to_add_trgconf.push(tid);
                }
            }
        }

        //if ("ran_addtr" in trconf)
        //{
        //    // 随机新增触发器
        //    local ran_addtr_conf = trconf.ran_addtr[0];
        //    local add_idxs = _n_choose_n(ran_addtr_conf.addtr, ran_addtr_conf.cnt);
        //    foreach (idx in add_idxs)
        //    {
        //        // 新增触发器                
        //        local add_ids = ran_addtr_conf.addtr[idx].ids;
        //        //sys.dumpobj( add_ids );
        //        foreach (addt in add_ids)
        //        {
        //            if (addt in this.trigger_conf ) 
        //            {
        //                to_add_trgconf.push(addt);
        //            }
        //        }
        //    }
        //}
        if (!string.IsNullOrEmpty(trconf.rmvtriger))
        {
            // 移除触发器
            foreach (string sx in trconf.rmvtriger.Split(','))
            {
                int rmvt = 0;
                int.TryParse(sx, out rmvt);
                if (rmvt <= 0)
                    continue;

                //if (rmvt in this.tmtriggers)
                //{
                //    to_rmv_tmtrgids.push(rmvt);
                //}
                //else if (rmvt in this.areatriggers)
                //{
                //    to_rmv_areatrgids.push(rmvt);
                //}
                //else 
                if (this.kmtriggers.ContainsKey(rmvt))
                {
                    to_rmv_kmtrgids.push(rmvt);
                }

                //else if (rmvt in this.useitmtriggers)
                //{
                //    to_rmv_uitmtrgids.push(rmvt);
                //}
                //else if (rmvt in this.mistriggers)
                //{
                //    to_rmv_mistrgids.push(rmvt);
                //}
                //else if (rmvt in this.othertriggers)
                //{
                //    to_rmv_othertrgids.push(rmvt);
                //}
            }
        }

        //if ("addnpc" in trconf)
        //{
        //    sys.trace(sys.SLT_DETAIL, "map[" + this.mapid + "] addnpc [" + trconf.id + "]\n");

        //    local cur_tm_s = sys.time();

        //    local add_npc = [];

        //    foreach (addnpc in trconf.addnpc)
        //    {
        //        local tmed_addnpc = addnpc;
        //        if (addnpc.dis_tm > 0)
        //        {
        //            tmed_addnpc = sys.deep_clone(addnpc);
        //            tmed_addnpc.dis_tm += cur_tm_s;
        //        }

        //        this.add_npcs.push(tmed_addnpc);
        //        add_npc.push(tmed_addnpc);
        //    }

        //    // broad add npc msg
        //    this.broadcast_map_rpc(6, { npcs = add_npc});

        //    //sys.dumpobj(add_npc);
        //}

        //if ("addlink" in trconf)
        //{
        //    //sys.trace(sys.SLT_DETAIL, "map["+this.mapid+"] addlink ["+trconf.id+"]\n");

        //    local cur_tm_s = sys.time();

        //    local addlinks = [];

        //    foreach (addlink in trconf.addlink)
        //    {
        //        local tmed_addlink = addlink;
        //        if (("dis_tm" in addlink) && addlink.dis_tm > 0)
        //        {
        //            tmed_addlink = sys.deep_clone(addlink);
        //            tmed_addlink.dis_tm += cur_tm_s;
        //        }

        //        tmed_addlink.to < -tmed_addlink.gto;
        //        this.add_links.push(tmed_addlink);
        //        addlinks.push(tmed_addlink);
        //    }

        //    // broad add npc msg
        //    this.broadcast_map_rpc(6, { links = addlinks});

        //    //sys.dumpobj(addlinks);
        //}

        //if ("rmvlink" in trconf)
        //{
        //    // TO DO : remove link
        //}

        //if ("modtrgtm" in trconf)
        //{
        //    // 修改倒计时触发器触发时间

        //    local cur_tm_s = sys.time();

        //    local tmtrigs = [];

        //    foreach (modtrgtm_conf in trconf.modtrgtm)
        //    {
        //        foreach (trid, trg in this.tmtriggers)
        //        {
        //            if (trid != modtrgtm_conf.tarid)
        //            {
        //                continue;
        //            }

        //            trg.tmleft += modtrgtm_conf.tmadd;

        //            if ("showid" in trg.conf.timer[0])
        //            {
        //                tmtrigs.push({ showid = trg.conf.timer[0].showid, tm = trg.tmleft + cur_tm_s});
        //            }
        //        }
        //    }

        //    if (tmtrigs.len() > 0)
        //    {
        //        // broad add npc msg
        //        this.broadcast_map_rpc(6, { tmtrigs = tmtrigs});
        //    }
        //}

        //if ("bcast" in trconf)
        //{
        //    // broad sys msg
        //    this.broadcast_map_rpc(160, { tp = 6, spec ={ tp = bcast_msg_tp.MAP_TRIGER_MSG, par = trconf.bcast}, msg = ""});
        //}

        //if (this.blvlmap)
        //{
        //    //sys.trace(sys.SLT_DETAIL, "map["+this.mapid+"] _trig_res ["+trconf.id+"] blvlmap with trig_spr["+trig_spr+"]\n");

        //    if (trig_spr)
        //    {
        //        if ("modatt" in trconf)
        //        {
        //            // 修改属性,如荣誉、经验值、游戏币等
        //            worldsvr._trig_modatt(trig_spr, trconf.modatt[0]);
        //        }

        //        if ("addstat" in trconf)
        //        {
        //            // 加buffer
        //            worldsvr._trig_addstat(trig_spr, trconf.addstat);
        //        }
        //    }
        //    else
        //    {
        //        if ("modatt" in trconf)
        //        {
        //            // 修改属性,如荣誉、经验值、游戏币等
        //            worldsvr._trig_modatt(null, trconf.modatt[0]);
        //        }
        //    }

        //    if ("vkm" in trconf)
        //    {
        //        // 虚拟杀怪
        //        worldsvr._trig_vkm(trig_spr, trconf.vkm, this);
        //    }

        //    if ("act_finchk" in trconf)
        //    {
        //        // 副本结束
        //        worldsvr._trig_active_finchk(trconf.act_finchk == 1);
        //    }

        //    if ("finlvl" in trconf)
        //    {
        //        // 副本结束
        //        worldsvr._trig_finlvl(trig_spr, trconf.finlvl, this);
        //    }
        //}
    }
Example #2
0
    public void _add_triger(trigger_conf trconf, long tm_elasped_s = 0)
    {

        //if ("timer" in trconf)
        //{
        //    //sys.trace(sys.SLT_DETAIL, "map["+this.mapid+"] add timer triger["+trconf.id+"]\n");

        //    local val = { tmleft = trconf.timer[0].tm - tm_elasped_s, cnt = trconf.timer[0].cnt, conf = trconf };
        //    this.tmtriggers[trconf.id] < -val;

        //    if ("showid" in trconf.timer[0])
        //    {
        //        // send add npc msg
        //        this.broadcast_map_rpc(6, { tmtrigs =[{ showid = trconf.timer[0].showid, tm = val.tmleft + sys.time()}]});
        //    }
        //}
        //else if ("area" in trconf)
        //{
        //    //sys.trace(sys.SLT_DETAIL, "map["+this.mapid+"] add area triger["+trconf.id+"]\n");

        //    this.areatriggers[trconf.id] < -trconf;
        //}
        //else 
        if (trconf.km != null)
        {
            //sys.trace(sys.SLT_DETAIL, "map["+this.mapid+"] add km triger["+trconf.id+"]\n");
            var tr_km_conf = trconf.km;
            var totalkmcnt = tr_km_conf.kmcnt;
            //if ("mulply" in tr_km_conf && tr_km_conf.mulply == 1 )
            //{
            //    totalkmcnt *= get_plycnt();
            //}
            this.kmtriggers[trconf.id] = new trigger_instance()
            {
                cnt = tr_km_conf.cnt,
                kmcnt = 0,
                tkmcnt = totalkmcnt,
                conf = trconf
            };

            //if ("showid" in trconf.km[0])
            //{
            //    // send add npc msg
            //    this.broadcast_map_rpc(6, { kmtrigs =[{ showid = tr_km_conf.showid, mid = tr_km_conf.mid, cnt = totalkmcnt, kmcnt = 0}]});
            //}
        }
        //else if ("useitm" in trconf)
        //{
        //    //sys.trace(sys.SLT_DETAIL, "map["+this.mapid+"] add useitm triger["+trconf.id+"]\n");

        //    this.useitmtriggers[trconf.id] < - { cnt = trconf.useitm[0].cnt, conf = trconf};
        //}
        //else if ("mis" in trconf)
        //{
        //    //sys.trace(sys.SLT_DETAIL, "map["+this.mapid+"] add useitm triger["+trconf.id+"]\n");

        //    this.mistriggers[trconf.id] < - { cnt = trconf.mis[0].cnt, conf = trconf};
        //}
        //else if ("other" in trconf)
        //{
        //    //sys.trace(sys.SLT_DETAIL, "map["+this.mapid+"] add other triger["+trconf.id+"]\n");

        //    this.othertriggers[trconf.id] < - { cnt = trconf.other[0].cnt, conf = trconf};
        //}
    }