コード例 #1
0
        public override bool SetupInstance(IPluginHost host, Dictionary <string, string> config, out string errorMsg)
        {
            //Create static instance
            if (Instance != null)
            {
                Instance = this;
            }

            //Register CustomObject
            host.TryRegisterType(typeof(CustomObject), (byte)EVENT_CODES.CO_CUSTOMOBJECT,
                                 PacketEncoder.Instance.EncodeCustomObject,
                                 PacketDecoder.Instance.DecodeCustomObject);

            //Register Player
            host.TryRegisterType(typeof(Player), (byte)EVENT_CODES.CO_PLAYER,
                                 PacketEncoder.Instance.EncodePlayer,
                                 PacketDecoder.Instance.DecodePlayer);

            //Register AI
            host.TryRegisterType(typeof(AI), (byte)EVENT_CODES.CO_AI,
                                 PacketEncoder.Instance.EncodeAI,
                                 PacketDecoder.Instance.DecodeAI);

            //Register AIState
            host.TryRegisterType(typeof(AIState), (byte)EVENT_CODES.CO_AISTATE,
                                 PacketEncoder.Instance.EncodeAIState,
                                 PacketDecoder.Instance.DecodeAIState);

            return(base.SetupInstance(host, config, out errorMsg));
        }
コード例 #2
0
 public static RaiseEventTestPlugin GetInstance()
 {
     if (Instance == null)
     {
         Instance = new RaiseEventTestPlugin();
     }
     return(Instance);
 }
コード例 #3
0
        public RaiseEventTestPlugin()
        {
            this.UseStrictMode = true;
            this.ServerString  = "ServerMessage";
            this.CallsCount    = 0;
            Instance           = this;

            // --- Connect to MySQL.
            ConnectToMySQL();
        }
コード例 #4
0
ファイル: PluginFactory.cs プロジェクト: XinYiGDT/FYPJ2
        public IGamePlugin Create(IPluginHost gameHost, string pluginName, Dictionary <string, string> config, out string errorMsg)
        {
            var plugin = new RaiseEventTestPlugin();

            if (plugin.SetupInstance(gameHost, config, out errorMsg))
            {
                return(plugin);
            }
            return(null);
        }
コード例 #5
0
        public void Update(object _plugin)
        {
            RaiseEventTestPlugin RETP = (RaiseEventTestPlugin)_plugin;

            isAlive        = true;
            m_statemanager = new StateManager <STATE>();
            m_statemanager.CurrstateReqUpdate = true;
            m_statemanager.AddUpdateFunction(STATE.IDLE, Idle);
            m_statemanager.AddUpdateFunction(STATE.CHASE, Chase);
            m_statemanager.AddUpdateFunction(STATE.ROAM, Roam);
            m_statemanager.AddUpdateFunction(STATE.ATTACK, Attack);

            m_statemanager.Currstate = m_statemanager.Prevstate = STATE.IDLE;
            while (isAlive)
            {
                //run AI Code
                lock (_info)
                {
                    m_statemanager.Update();
                    RETP.SendMessage(103, MonsterInfo.Serialize(_info));
                    if (_newinfo != null)
                    {
                        lock (_newinfo)
                        {
                            _info.playerposx = _newinfo.playerposx;
                            _info.playerposz = _newinfo.playerposz;
                            _info.playerhp   = _newinfo.playerhp;
                            _info.hp         = _newinfo.hp;
                            _newinfo         = null;
                        }
                    }
                }
                CustomObject co = new CustomObject();
                co.Init();
                co.message = "Update Success " + m_statemanager.Currstate.ToString();
                RETP.SendMessage(169,
                                 CustomObject.Serialize(co)
                                 );
                System.Threading.Thread.Sleep(500);
            }
        }
コード例 #6
0
        /// <summary>
        /// This is the other thread that handles the AI
        /// Main thread is the RaiseEvent
        /// </summary>
        public void ThreadOfAI()
        {
            // ---- Website did this, so i do this ( smth abt ensuring that update only this )
            lock (obj)
            {
                // Get the currently running thread
                var thread = Thread.CurrentThread;

                // ensure main thread is started before updating this thread
                while (RaiseEventTestPlugin.GetInstance() == null)
                {
                    Thread.Sleep(100);
                }

                // ---- Start updating this thread
                // Initialise list
                m_AIList = new List <EnemyAI>();

                // Spawn enemies in list
                SpawnEnemy("EnemyName " + m_ID.ToString(), new Vector3(10.0f, 0.0f, 10.0f));
                SpawnEnemy("EnemyName " + m_ID.ToString(), new Vector3(20.0f, 0.0f, 20.0f));
                SpawnEnemy("EnemyName " + m_ID.ToString(), new Vector3(30.0f, 0.0f, 30.0f));

                // Update the enemies
                while (true)
                {
                    //RaiseEventTestPlugin.GetInstance().PluginHost.BroadcastEvent(target: ReciverGroup.All,
                    //                                                                 senderActor: 0,
                    //                                                                 targetGroup: 0,
                    //                                                                 evCode: (byte)99,
                    //                                                                 data: new Dictionary<byte, object>() { { (byte)245, "entered while loop" } },
                    //                                                                 cacheOp: 0);

                    // Update each enemy
                    foreach (EnemyAI enemy in Instance.m_AIList)
                    {
                        enemy.Update();

                        // set target packet to send to be player
                        //foreach (Player player in RaiseEventTestPlugin.GetInstance().m_playerList)
                        //{
                        //enemy.SetTargetPacket(player.GetName());


                        // send over to client to update the Enemy obj position
                        byte[] store = Packet_Serialisation.GetInstance().SerializeCustomAI(enemy);
                        //RaiseEventTestPlugin.GetInstance().PluginHost.BroadcastEvent(target: ReciverGroup.All,
                        //                                                                 senderActor: 0,
                        //                                                                 targetGroup: 0,
                        //                                                                 evCode: (byte)99,
                        //                                                                 data: new Dictionary<byte, object>() { { (byte)245, "entered while loop" } },
                        //                                                                 cacheOp: 0);
                        //RaiseEventTestPlugin.GetInstance().PluginHost.BroadcastEvent(target: ReciverGroup.All,
                        //                                                             senderActor: 0,
                        //                                                             targetGroup: 0,
                        //                                                             evCode: (byte)13,
                        //                                                             data: new Dictionary<byte, object>() { { (byte)245, store } },
                        //                                                             cacheOp: 0);
                        //}
                    }
                    Thread.Sleep(100); // 0.1s
                }
            }
        }
コード例 #7
0
ファイル: EnemyAI.cs プロジェクト: hotaru08/PhotonAs2
        /// <summary>
        /// Handles the Changing of Enemy States
        /// </summary>
        private void ChangingOfStates()
        {
            // ---- Check for all Players in the PlayerList
            foreach (Player player in RaiseEventTestPlugin.GetInstance().m_playerList)
            {
                // ---- If the Distance from Enemy AI to Player is lesser than (_blank_), change to CHASE
                if (DistanceFromPlayer(player) > 4 * 4 && DistanceFromPlayer(player) < 10 * 10)
                {
                    // ---- Choose the nearest Player
                    if (player.GetPosition().x < m_nearestPlayerPos.x &&
                        player.GetPosition().z < m_nearestPlayerPos.z)
                    {
                        // update nearest player pos
                        m_nearestPlayerPos = player.GetPosition();
                        // set new target
                        m_targetPos    = player.GetPosition();
                        m_playerTarget = player;
                    }

                    // save previous position of AI
                    if (!m_bSavePrevPos)
                    {
                        m_prevPos      = this.GetPosition();
                        m_bSavePrevPos = true;
                    }

                    m_state = "CHASE";
                }
                // ---- If the Distance from Enemy AI to Player is lesser than (_blank_), change to ATTACK
                else if (DistanceFromPlayer(player) < 4 * 4)
                {
                    // If a Player suddenly intercepts, change target
                    if (player.GetPosition().x < m_nearestPlayerPos.x &&
                        player.GetPosition().z < m_nearestPlayerPos.z)
                    {
                        // update nearest player pos
                        m_nearestPlayerPos = player.GetPosition();
                        // set new target
                        m_targetPos    = player.GetPosition();
                        m_playerTarget = player;
                    }

                    m_state = "ATTACK";
                }
                // ---- If the Distance from Enemy AI to Player is more than (_blank_), change to RETURN
                else if (DistanceFromPlayer(player) >= 10 * 10 &&
                         !(this.GetPosition().x == m_prevPos.x &&
                           this.GetPosition().z == m_prevPos.z))
                {
                    m_state = "RETURN";
                }
                else
                {
                    m_state = "ROAM";
                }
            }

            RaiseEventTestPlugin.GetInstance().PluginHost.BroadcastEvent(target: ReciverGroup.All,
                                                                         senderActor: 0,
                                                                         targetGroup: 0,
                                                                         evCode: (byte)99,
                                                                         data: new Dictionary <byte, object>()
            {
                { (byte)245, "State : " + m_state }
            },
                                                                         cacheOp: 0);
        }