Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CLevelBot
- {
- CTeleport m_teleport_engine;
- uint m_player_vid;
- uint m_current_time;
- uint m_dead_time;
- array <uint> m_enemies;
- array <uint> m_pots;
- uint m_last_attack;
- int m_start_x;
- int m_start_y;
- int m_point_x;
- int m_point_y;
- int m_cur_tp;
- int m_max_tp;
- int m_tp_percent;
- bool m_enabled;
- bool m_player_at_point;
- bool m_cur_tp_set;
- bool m_was_dead;
- bool m_first_start;
- array<item@> m_items;
- uint m_pick_vid;
- CLevelBot()
- {
- this.m_enabled = false;
- this.m_start_x = 0;
- this.m_start_y = 0;
- this.m_point_x = 0;
- this.m_point_y = 0;
- this.m_last_attack = 0;
- this.m_dead_time = 0;
- this.m_current_time = 0;
- this.m_player_vid = 0;
- this.m_player_at_point = false;
- this.m_cur_tp_set = false;
- this.m_was_dead = false;
- this.m_first_start = true;
- this.m_pick_vid = 0;
- this.m_cur_tp = 0;
- this.m_max_tp = 0;
- this.m_tp_percent = 0;
- for(int i = 0; i < 90; i++)
- {
- this.m_pots.insertLast(0);
- }
- }
- void Enable(bool enabled)
- {
- this.m_enabled = enabled;
- if(enabled)
- SYSLOG("Level Bot enabled!");
- else
- SYSLOG("Level Bot disabled!");
- };
- void SetPlayerVID(uint vid)
- {
- this.m_player_vid = vid;
- this.m_start_x = find_entity(vid).get_x();
- this.m_start_y = find_entity(vid).get_y();
- this.m_teleport_engine.set_vid(vid);
- };
- void OnStartup()
- {
- if(cfg.get_string("bot.type","") == "levelbot")
- this.Enable(true);
- };
- void OnCleanup()
- {
- };
- void SetLevelPos(entity@ p)
- {
- int level = p.get_level();
- int map = maps.GetMapByPos(p.get_x(), p.get_y());
- int point_x = 0;
- int point_y = 0;
- for(uint i = 0; i < cfg.get_int("point." + map + ".PointCount", 0); i++)
- {
- if(cfg.get_int("point." + map+ "." + i + ".Type", 0) == 3
- && level >= cfg.get_int("point." + map + "." + i + ".LvMin", 0)
- && level <= cfg.get_int("point." + map + "." + i + ".LvMax", 0))
- {
- point_x = ((cfg.get_int("point." + map + "." + i + ".PosX", 0)*100) + maps.m_map_base[map][0]);
- point_y = ((cfg.get_int("point." + map + "." + i + ".PosY", 0)*100) + maps.m_map_base[map][1]);
- //DEVLOG("LEVELPOINT FOUND! X: " + point_x + " Y: " + point_y + " Lv: " + level);
- //DEVLOG("this.m_first_start: " + this.m_first_start + " this.m_player_at_point: " + this.m_player_at_point);
- if((abs(p.get_x() - this.m_point_x) < 10000 && abs(p.get_y() - this.m_point_y) < 10000) && !this.m_first_start)
- this.m_player_at_point = true;
- else if((point_x != 0 && point_y != 0))
- {
- this.m_point_x = point_x;
- this.m_point_y = point_y;
- this.m_teleport_engine.set_destination(this.m_point_x, this.m_point_y);
- DEVLOG("Setting destination..");
- this.m_player_at_point = false;
- this.m_first_start = false;
- } else {
- this.m_player_at_point = true;
- }
- };
- };
- };
- void OnTick(uint current)
- {
- if(!this.m_enabled || this.m_player_vid == 0)
- return;
- entity@ p = find_entity(this.m_player_vid);
- SetLevelPos(p);
- if(!this.m_teleport_engine.is_teleporting() && !UsePotions() && !this.m_first_start) {
- if(this.m_was_dead)
- if(this.m_tp_percent < 80)
- return;
- this.m_was_dead = false;
- PickItems(p);
- if(current - this.m_last_attack >= 125 && this.m_player_at_point) {
- uint hit_count = 0;
- for(uint x = 0; x < get_entity_count(); ++x) {
- entity@ e = get_entity(x);
- if(e.get_type() != entity_mob)
- continue;
- if(this.m_enemies.find(e.get_vid())==-1)
- continue;
- int64 moblevel = parseInt(mob_proto_get(e.get_race(),"level"));
- if(moblevel > p.get_level()+5)
- continue;
- uint distx = abs(p.get_x()-e.get_x());
- uint disty = abs(p.get_y()-e.get_y());
- uint distance = sqrt((distx*distx)+(disty*disty));
- if(distance > 500)
- continue;
- net.send_attack(0,e.get_vid());
- ++hit_count;
- this.m_last_attack = current;
- }
- if(hit_count == 0 && this.m_player_at_point) {
- for(uint x = 0; x < get_entity_count(); ++x) {
- entity@ e = get_entity(x);
- if(e.get_type() != entity_mob)
- continue;
- if(this.m_enemies.find(e.get_vid())==-1)
- continue;
- int64 moblevel = parseInt(mob_proto_get(e.get_race(),"level"));
- if(moblevel > p.get_level()+3)
- continue;
- uint distance_x = abs(e.get_x() - this.m_point_x);
- uint distance_y = abs(e.get_y() - this.m_point_y);
- uint distance = sqrt((distance_x*distance_x)+(distance_y*distance_y));
- if(distance < 10000) {
- this.m_teleport_engine.set_destination(e.get_x(),e.get_y());
- break;
- }
- }
- this.m_last_attack = 0;
- }
- }
- }
- this.m_teleport_engine.tick();
- this.m_current_time = current;
- };
- void OnPointChange(uint vid, uint type, int amount, int value)
- {
- if(type >= 83886090 && type <= 83886999) // HP
- {
- this.m_cur_tp = value;
- this.m_cur_tp_set = true;
- }
- if(!this.m_cur_tp_set)
- this.m_cur_tp = this.m_max_tp;
- if(this.m_max_tp != 0 && this.m_cur_tp != 0)
- this.m_tp_percent = ceil((this.m_cur_tp*100)/this.m_max_tp);
- DEVLOG("tp_percent: " + this.m_tp_percent + ", cur_tp: " + this.m_cur_tp + ", max_tp: " + this.m_max_tp);
- DEVLOG("type: " + type + ", amount: " + amount + ", value: " + value);
- };
- void OnItemSet(uint8 pos, uint vnum, uint8 count, uint flags)
- {
- DEVLOG("ITEM SET - " + pos + ", " + vnum + ", " + count + ", " + flags);
- if(vnum == 27001 || vnum == 27002 || vnum == 27003)
- this.m_pots[pos] = count;
- };
- bool UsePotions()
- {
- if(this.m_tp_percent < 70 && this.m_max_tp > 10 && this.m_cur_tp_set)
- {
- for(int i = 0; i < 90; i++)
- if(this.m_pots[i] > 0)
- net.send_item_use(i);
- }
- return false;
- };
- void PickItems(entity@ p)
- {
- int old_x = p.get_x();
- int old_y = p.get_y();
- if(this.m_player_at_point && !this.m_teleport_engine.is_teleporting())
- {
- if(this.m_pick_vid == 0 && this.m_items.length() > 0 && !this.m_teleport_engine.is_teleporting()) {
- item@ i = this.m_items[0];
- this.m_pick_vid = i.get_vid();
- this.m_teleport_engine.set_destination(i.get_x(),i.get_y());
- }
- if(this.m_pick_vid != 0 && !this.m_teleport_engine.is_teleporting()) {
- item@ i = find_item(this.m_pick_vid);
- if(i.get_vnum() == 27001 || i.get_vnum() == 27002 || i.get_vnum() == 27003 || i.get_vnum() == 1)
- net.send_pick_up(this.m_pick_vid);
- int idx = this.m_items.find(i);
- if(idx != -1)
- this.m_items.removeAt(idx);
- this.m_pick_vid = 0;
- }
- }
- };
- void OnCharacterAdd(entity@ e)
- {
- this.m_enemies.insertLast(e.get_vid());
- };
- void OnCharacterDelete(entity@ e)
- {
- int idx = this.m_enemies.find(e.get_vid());
- if(idx != -1)
- this.m_enemies.removeAt(idx);
- };
- void OnCharacterDead(entity@ e)
- {
- if(e.get_vid() == this.m_player_vid) {
- while(this.m_enemies.length() > 0)
- this.m_enemies.removeAt(0);
- this.m_player_vid = 0;
- this.m_teleport_engine.set_vid(0);
- this.m_was_dead = true;
- net.connect(net.get_ip(),net.get_port());
- }
- int idx = this.m_enemies.find(e.get_vid());
- if(idx != -1)
- this.m_enemies.removeAt(idx);
- };
- void OnCharacterUpdate(entity@ e)
- {
- };
- void OnWarp(int x, int y, string addr, uint port)
- {
- };
- void OnItemGroundAdd(item@ i)
- {
- this.m_items.insertLast(i);
- };
- void OnItemGroundDelete(item@ i)
- {
- int idx = this.m_items.find(i);
- if(i.get_vid() == this.m_pick_vid)
- this.m_pick_vid = 0;
- if(idx != -1)
- this.m_items.removeAt(idx);
- };
- void OnItemOwnership(item@ i)
- {
- int idx = this.m_items.find(i);
- if(i.get_owner() == this.m_player_vid || i.get_owner() == 0) {
- if(idx == -1)
- this.m_items.insertLast(i);
- } else {
- if(i.get_vid() == this.m_pick_vid)
- this.m_pick_vid = 0;
- if(idx != -1)
- this.m_items.removeAt(idx);
- }
- };
- void OnPointsSet(array<int> pts)
- {
- if(pts[6] != 0)
- this.m_max_tp = pts[6];
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement