Inheritance: ConcreteObject, ILivingObject
示例#1
0
 public ManualControlAI(LivingObject worker, int playerID)
 {
     this.Worker  = worker;
     m_playerID   = playerID;
     m_actions    = new ObservableCollection <GameAction>();
     this.Actions = new ReadOnlyObservableCollection <GameAction>(m_actions);
 }
示例#2
0
 public ManualControlAI(LivingObject worker, int playerID)
 {
     this.Worker = worker;
     m_playerID = playerID;
     m_actions = new ObservableCollection<GameAction>();
     this.Actions = new ReadOnlyObservableCollection<GameAction>(m_actions);
 }
示例#3
0
 public ManualControlAI(LivingObject worker, byte aiID)
 {
     this.Worker = worker;
     m_id = aiID;
     m_actions = new ObservableCollection<GameAction>();
     this.Actions = new ReadOnlyObservableCollection<GameAction>(m_actions);
 }
示例#4
0
 public void RequestAction(GameAction action)
 {
     if (LivingObject.LivingRequestsAction != null)
     {
         LivingObject.LivingRequestsAction(this, action);
     }
 }
示例#5
0
        void OnLivingRequestsAction(LivingObject living, GameAction action)
        {
            turnTrace.TraceVerbose("SignalLivingHasAction({0}, {1}", living, action);

            if (m_world.IsOurTurn == false)
            {
                turnTrace.TraceWarning("SignalLivingHasAction when not our turn");
                return;
            }

            m_actionMap[living] = action;

            SendProceedTurn();
        }
        public static void SendSetLivingTraceLevel(LivingObject living, System.Diagnostics.TraceLevel traceLevel)
        {
            var args = new Dictionary <string, object>()
            {
                { "livingID", living.ObjectID },
                { "traceLevel", traceLevel.ToString() },
            };

            var script =
                @"l = world.GetObject(livingID)
t = l.Trace
tl = t.TraceLevel.Parse(t.TraceLevel.GetType(), traceLevel)
t.TraceLevel = tl
";

            var msg = new Dwarrowdelf.Messages.IPScriptMessage(script, args);

            GameData.Data.User.Send(msg);
        }
示例#7
0
        public void SendProceedTurn()
        {
            turnTrace.TraceVerbose("SendProceedTurn");

            if (m_world.IsOurTurn == false)
            {
                turnTrace.TraceWarning("SendProceedTurn when not our turn");
                return;
            }

            if (m_proceedTurnSent)
            {
                turnTrace.TraceWarning("SendProceedTurn when proceed turn already sent");
                return;
            }

            var list = new List <KeyValuePair <ObjectID, GameAction> >();

            IEnumerable <LivingObject> livings;

            if (m_world.CurrentLivingID == ObjectID.AnyObjectID)
            {
                // livings which the user can control (ie. server not doing high priority action)
                livings = m_world.Controllables.Where(l => l.UserActionPossible());
            }
            else
            {
                var living = m_world.GetObject <LivingObject>(m_world.CurrentLivingID);
                if (living.UserActionPossible() == false)
                {
                    throw new NotImplementedException();
                }
                livings = new LivingObject[] { living };
            }

            var focusedObject = this.FocusedObject;

            foreach (var living in livings)
            {
                GameAction action;

                if (m_actionMap.TryGetValue(living, out action) == false)
                {
                    // skip AI if we're directly controlling the living
                    if (focusedObject != living)
                    {
                        action = living.DecideAction();
                    }
                    else
                    {
                        action = living.CurrentAction;
                    }
                }

                Debug.Assert(action == null || action.GUID.IsNull == false);

                if (action != living.CurrentAction)
                {
                    turnTrace.TraceVerbose("{0}: selecting new action {1}", living, action);
                    list.Add(new KeyValuePair <ObjectID, GameAction>(living.ObjectID, action));
                }
            }

            m_user.Send(new Dwarrowdelf.Messages.ProceedTurnReplyMessage()
            {
                Actions = list.ToArray()
            });

            m_proceedTurnSent = true;
            m_actionMap.Clear();
        }
示例#8
0
		public void SendProceedTurn()
		{
			turnTrace.TraceVerbose("SendProceedTurn");

			if (m_world.IsOurTurn == false)
			{
				turnTrace.TraceWarning("SendProceedTurn when not our turn");
				return;
			}

			if (m_proceedTurnSent)
			{
				turnTrace.TraceWarning("SendProceedTurn when proceed turn already sent");
				return;
			}

			var list = new List<Tuple<ObjectID, GameAction>>();

			IEnumerable<LivingObject> livings;

			if (m_world.CurrentLivingID == ObjectID.AnyObjectID)
			{
				// livings which the user can control (ie. server not doing high priority action)
				livings = m_world.Controllables.Where(l => l.UserActionPossible());
			}
			else
			{
				var living = m_world.GetObject<LivingObject>(m_world.CurrentLivingID);
				if (living.UserActionPossible() == false)
					throw new NotImplementedException();
				livings = new LivingObject[] { living };
			}

			var focusedObject = App.MainWindow.FocusedObject;

			foreach (var living in livings)
			{
				GameAction action;

				if (m_actionMap.TryGetValue(living, out action) == false)
				{
					// skip AI if we're directly controlling the living
					if (focusedObject != living)
						action = living.DecideAction();
					else
						action = living.CurrentAction;
				}

				Debug.Assert(action == null || action.MagicNumber != 0);

				if (action != living.CurrentAction)
				{
					turnTrace.TraceVerbose("{0}: selecting new action {1}", living, action);
					list.Add(new Tuple<ObjectID, GameAction>(living.ObjectID, action));
				}
			}

			Send(new ProceedTurnReplyMessage() { Actions = list.ToArray() });

			m_proceedTurnSent = true;
			m_actionMap.Clear();
		}
示例#9
0
		void OnLivingRequestsAction(LivingObject living, GameAction action)
		{
			turnTrace.TraceVerbose("SignalLivingHasAction({0}, {1}", living, action);

			if (m_world.IsOurTurn == false)
			{
				turnTrace.TraceWarning("SignalLivingHasAction when not our turn");
				return;
			}

			m_actionMap[living] = action;

			SendProceedTurn();
		}
示例#10
0
        public static void SendSetLivingTraceLevel(LivingObject living, System.Diagnostics.TraceLevel traceLevel)
        {
            var args = new Dictionary<string, object>()
            {
                { "livingID", living.ObjectID },
                { "traceLevel", traceLevel.ToString() },
            };

            var script =
            @"l = world.GetObject(livingID)
            t = l.Trace
            tl = t.TraceLevel.Parse(t.TraceLevel.GetType(), traceLevel)
            t.TraceLevel = tl
            ";

            var msg = new Dwarrowdelf.Messages.IPScriptMessage(script, args);

            GameData.Data.User.Send(msg);
        }