[Impulse's source][Release]Part code for Duelist

05/26/2010 20:41 MonstersAbroad#1
Heres abit of code for Impulse's 5165 source recently released this is 25% of the code for AIDuelist
well I used a hashtable and added this into GameState.cs
Code:
 public void DuelistTest()
        {
            Game.Entity duelist = new Game.Entity(Game.EntityFlag.Bot);
            duelist.MapObjType = Game.MapObjectType.Bot;
            this.BotOwner = Entity;
            BotOwner = Entity;
            duelist.Name = Entity.Name + "[BOT]";
            duelist.X = Entity.X += 1;
            duelist.Y = Entity.Y += 1;
            duelist.Dodge = Entity.Dodge *= 2;
            duelist.Defence = Entity.Defence *= 2;
            duelist.MapID = Entity.MapID;
            duelist.Body = Entity.Body;
            duelist.Hitpoints = Entity.MaxHitpoints;
            duelist.Level = Entity.Level;
            duelist.Stamina = 250;
            duelist.Face = Entity.Face;
            duelist.Facing = Entity.Facing;
            duelist.HairColor = Entity.HairColor;
            duelist.HairStyle = Entity.HairStyle;
            duelist.Strength = 750;
            duelist.Agility = 750;
            duelist.Spirit = 750;
            duelist.Vitality = 750;
            duelist.Spouse = "TheServer";
            duelist.MinAttack = 500;
            duelist.MaxAttack = 3000;
            duelist.BaseMinAttack = 500;
            duelist.BaseMaxAttack = 3000;
            duelist.BaseMagicDefence = 300;
            duelist.BaseMagicAttack = 5000;
            duelist.Class = Entity.Class;
            duelist.ItemBless = Entity.ItemBless;
            duelist.ItemHP = Entity.ItemHP;
            duelist.ItemMP = Entity.ItemMP;
            duelist.PKMode = Game.Enums.PKMode.PK;
            // entity.UID = 400001;
            duelist.UID = (uint)ServerBase.Kernel.Random.Next(400000, 500000);
            ServerBase.Kernel.Bots.Add(duelist.UID, this);
            duelist.SendSpawn(this);
        }
        public void DuelistTestMove()
        {
            if (DateTime.Now > LastBotMove.AddMilliseconds(250))
            {
                LastBotMove = DateTime.Now;
                if (Game.Attacking.Calculate.PointDistance(BotOwner.X, BotOwner.Y, Entity.X, Entity.Y) >= 4)
                {
                    DuelistJumpAround();
                }
            }
        }
        void DuelistJumpAround()
        {
            BotOwner.X = (ushort)(Entity.X + ServerBase.Kernel.Random.Next(7) - ServerBase.Kernel.Random.Next(7));
            BotOwner.Y = (ushort)(Entity.Y + ServerBase.Kernel.Random.Next(7) - ServerBase.Kernel.Random.Next(7));
            BotOwner.Action = Game.Enums.ConquerAction.Jump;
        }
and these
Code:
        public static DateTime LastBotMove = DateTime.Now;
        public static DateTime LastBotAttack = DateTime.Now;
        public static bool BotInUse = false;
        public Game.Entity BotOwner;
in kernel.cs I made the top look like
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
and then added
Code:
public static Hashtable Bots = new Hashtable();
In program.cs I added
Code:
        static void BotThread_Execute()
        {
           
        }
and I added
Code:
ServerBase.Thread BotThread = new ServerBase.Thread(10);
                BotThread.Execute += new Action(BotThread_Execute);
and the
Code:
GC.KeepAlive(CharacterThread); GC.KeepAlive(FloorItems); GC.KeepAlive(StatusFlagChange);
I made look like
Code:
GC.KeepAlive(CharacterThread); GC.KeepAlive(FloorItems); GC.KeepAlive(StatusFlagChange); GC.KeepAlive(BotThread);
then added the command in packerhandler.cs
Code:
case "bot":
                                        {
                                            client.DuelistTest();
                                            break;
                                        }
About 25% done. OH I also find
Code:
public enum EntityFlag : byte
    {
and make it look like
Code:
        Player = 1,
        Monster = 2,
        Bot = 3
then find
Code:
 public enum MapObjectType
    {
and make it look like
Code:
    public enum MapObjectType
    {
        Npc, Item, Monster, Player, Nothing, InvalidCast, Bot
    }
again as I said 25% done. Wrote this thread kinda quickly p.s not tested jumping.
05/26/2010 21:15 BlueFlame11#2
I already pressed thanks on the other thread so no need for it here =P
05/26/2010 21:19 MonstersAbroad#3
Thanks, =P I do plan to complete this too :D
05/26/2010 23:16 CIRASH#4
Isn't a dictionary better to use because hashtables have depreciated since .Net 2.0, right?
05/26/2010 23:24 ~Yuki~#5
exactly
05/27/2010 00:06 pro4never#6
Quote:
Originally Posted by CIRASH View Post
Isn't a dictionary better to use because hashtables have depreciated since .Net 2.0, right?
Yah not sure why he switched to hashtable.. i mean the code i posted for it used dict... ahh well it's an easy change.
05/27/2010 00:11 hunterman01#7
You have to admit though his coding skills have definatly improved
05/27/2010 17:17 MonstersAbroad#8
The hashtable for me atm is easyer but as said easy to change ill do that later for now its testing stage,
05/27/2010 17:52 Korvacs#9
Quote:
Originally Posted by MonstersAbroad View Post
The hashtable for me atm is easyer but as said easy to change ill do that later for now its testing stage,
Using a hashtable will reduce performance drastically just so you know.
05/27/2010 18:32 MonstersAbroad#10
I understand, I will change to a dict soon.
05/27/2010 18:38 xScott#11
interesting :O i wanna see if i can attempt this using Elite-CoEmu, just the basics thou like spawning the bot.

Goodjob
05/27/2010 22:03 pro4never#12
Quote:
Originally Posted by xScott View Post
interesting :O i wanna see if i can attempt this using Elite-CoEmu, just the basics thou like spawning the bot.

Goodjob
Note that I already released almost full working code for EliteCoEmu (before I added actions/ai) but it spawns and everything else works properly.

Refer to my project thread... like 2-3 posts down.

<edit>

released the entire test source for simplicity sake

[Only registered and activated users can see links. Click Here To Register...]