/// <summary> /// Decoding for AI - Decoding format: TargetReceiverName, ObjectName, ObjectHealth, ObjectPosX, ObjectPosY, ObjectPosZ, ObjectRotX, ObjectRotY, ObjectRotZ, ObjectRotW, StateName, StateRange, StateTargetPosX, StateTargetPosY, StateTargetPosZ /// </summary> public object DecodeAI(byte[] bytes) { AI customObject = new AI(); AIState currentState = new AIState(); using (var s = new MemoryStream(bytes)) { using (var br = new BinaryReader(s)) { //CustomObject Data customObject.SetPacketTarget(br.ReadString()); customObject.SetObjectName(br.ReadString()); customObject.SetHealth(br.ReadInt32()); customObject.SetPos(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); customObject.SetRot(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); //AIState Data currentState.SetName(br.ReadString()); currentState.SetRange(br.ReadSingle()); currentState.SetTarget(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), new Quaternion()); //AI Data customObject.GetStateMachine().SetCurrState(currentState.GetName()); return(customObject); } } }
public static void SpawnAI(string name, int health, Vector3 position, List <AIState> statesToAdd) { AI enemy = new AI(); enemy.SetObjectName(name + Instance.aiID); enemy.SetHealth(health); enemy.SetPos(position); enemy.AddState(statesToAdd); enemy.GetStateMachine().SetCurrState(statesToAdd[0].GetName()); //Add AI to the list of managed AIs AddAI(enemy); //Increase unique ID count ++Instance.aiID; //Sleep Thread to allow Random generator to get new seed Thread.Sleep(10); }