Пример #1
0
 public World()
 {
     watch.Start();
     updateDomains = new UpdateDomain[1];
     updateDomains[0] = new UpdateDomain(watch);
     State = WorldState.Running;
 }
Пример #2
0
    //check if the worldstate contains the same properties as the worldstate ws (can still contain other as well)
    public bool Contains(WorldState ws)
    {
        Dictionary<string, WorldStateValue> wsProperties = ws.GetProperties();

        foreach(KeyValuePair<string, WorldStateValue> pair in wsProperties)
        {
            if(properties.ContainsKey(pair.Key)) //if both contains the same property key
            {

                if(properties[pair.Key].propertyValues["bool"].Equals(pair.Value.propertyValues["bool"])) //if they both also have the same value
                {
                    continue;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        return true;
    }
Пример #3
0
    GameObject agentObject; //the agent gameObject

    #endregion Fields

    #region Methods

    public void OnTriggerEnter(Collider other)
    {
        colliderList.Add(other); //add detected object to list of "seen" objects
        if (other.gameObject.name == "Resource(Clone)") { //if it is a resource
            Debug.Log("Found " + other.tag + "!");

            //get color of resource
            string color = "";
            for(int i = 1; i < other.tag.Length; i++)
            {
                if(char.IsUpper(other.tag[i]))
                {
                    color = other.tag.Substring(0, i);
                    break;
                }
            }

            //update the workingmemory that a resource is at this position
            ((Agent)agentComponent).GetWMemory().SetFact(color, new WorkingMemoryValue(other.transform.position));

            //update the currentWorldState that resrouces of this color is available
            WorldState newState = new WorldState();
            newState.SetProperty(char.ToLower(color[0]) + color.Substring(1) + "ResourceIsAvailable", new WorldStateValue(true));
            BlackBoard.Instance.SetCurrentWorldstate(agentComponent.GetClan(), newState);
        }
    }
Пример #4
0
    //create a new plan if old plan fails for example
    public void CreateNewPlan(WorldState currentWorldState, WorldState goalWorldState)
    {
        StopCoroutine(plan[0].Substring(0, plan[0].Length - 6));
        Destroy(transform.FindChild("Subsystem").gameObject);

        planner.SetGoalWorldState(goalWorldState);

        //Saves current plan so that agent can continue after new plan is completed
        List<string> tempPlan = new List<string>();
        foreach(string action in plan)
        {
            tempPlan.Add(action);
        }

        List<string> newPlanList = new List<string>();
        foreach (AStarNode node in planner.RunAStar(currentWorldState))
        {
            newPlanList.Add(node.GetName());
        }

        if(newPlanList.Count == 0)
        {
            //A new plan could not be made so continue on the old plan
            //Implement some kind of report up to commanders?
            Debug.Log("NEW PLAN COULD NOT BE MADE!!");
        } else
        {
            //A new plan was created, is added in front of old plan
            plan.Clear();
            plan.Add ("Crap"); //Added because remove plan[0] in update
            plan.InsertRange(1, newPlanList);
            plan.InsertRange(plan.Count, tempPlan);
        }
    }
Пример #5
0
    //get the neighbours of this node
    public List<AStarNode> GetNeighbours(bool  firstTime)
    {
        List<Action> tempList = new List<Action>();
        WorldState preConditions = new WorldState();

        if(firstTime == true)//if first node in the AStar then it will be a postCondition
        {
            preConditions = worldState;
        }
        else{ //else it will be an action so get the preconditions of that action

            preConditions = ActionManager.Instance.GetAction(this.name).preConditions;
        }

        tempList = ActionManager.Instance.GetSuitableActions(preConditions);

        foreach(Action action in tempList)
        {
            AStarNode node = new AStarNode();
            node.name = action.GetActionName();
            node.parent = this;
            node.time = action.time;

            suitableActions.Add(node);
        }
        return suitableActions;
    }
Пример #6
0
        /// <summary>
        /// Render the terrain
        /// </summary>
        /// <param name="device"></param>
        /// <param name="world"></param>
        public override void Draw(GraphicsDevice device, WorldState world)
        {
            world._3D.ApplyCamera(Effect, this);
            //device.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
            //device.SamplerStates[0].AddressV = TextureAddressMode.Wrap;

            device.SetVertexBuffer(VertexBuffer);
            device.Indices = IndexBuffer;

            //device.RasterizerState.CullMode = CullMode.None;
            foreach (var pass in Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, GeomLength, 0, NumPrimitives);
            }

            device.SetVertexBuffer(GrassVertexBuffer);
            //device.Indices = GrassIndexBuffer;

            foreach (var pass in Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawPrimitives(PrimitiveType.LineList, 0, GrassPrimitives);
                //device.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, GrassPrimitives*2, 0, GrassPrimitives);
            };
        }
Пример #7
0
    public List<AStarNode> RunAStar(WorldState currentWorldState)
    {
        AStarNode startNode = new AStarNode();
        AStarNode endNode = new AStarNode();

        startNode.SetWorldState(goalWorldState);
        endNode.SetWorldState(currentWorldState);

        AStar star = new AStar();

        List<AStarNode> plan = star.Run(startNode, endNode);

        //används under utvecklingsfasen
        /*Debug.Log("HÄR ÄR PLANEN!!!!!!!!: " + plan.Count);
        foreach(AStarNode node in plan)
        {
            Debug.Log(node.name);
        }*/
        //----------------------------

        /*foreach(AStarNode node in plan)
        {
            //TODO: dubbelkolla att returnerande action faktiskt finns
            blackBoard.setCurrentAction(node.name);

        }*/
        //blackBoard.setCurrentAction("");

        return plan;
    }
Пример #8
0
    public bool contains(WorldState ws)
    {
        Dictionary<string, WorldStateValue> wsProperties = ws.getProperties();

        foreach(KeyValuePair<string, WorldStateValue> pair in properties)
        {
            if(ws.getProperties().ContainsKey(pair.Key))
            {

                if(wsProperties[pair.Key].propertyValues["bool"].Equals(pair.Value.propertyValues["bool"]))
                {
                    continue;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        return true;
    }
        private _2DSprite GetAirSprite(WorldState world)
        {
            var _Sprite = new _2DSprite()
            {
                RenderMode = _2DBatchRenderMode.Z_BUFFER
            };
            var airTiles = TextureGenerator.GetAirTiles(world.Device);
            Texture2D sprite = null;
            switch (world.Zoom)
            {
                case WorldZoom.Far:
                    sprite = airTiles[2];
                    _Sprite.DestRect = FLOORDEST_FAR;
                    _Sprite.Depth = ArchZBuffers[14];
                    break;
                case WorldZoom.Medium:
                    sprite = airTiles[1];
                    _Sprite.DestRect = FLOORDEST_MED;
                    _Sprite.Depth = ArchZBuffers[13];
                    break;
                case WorldZoom.Near:
                    sprite = airTiles[0];
                    _Sprite.DestRect = FLOORDEST_NEAR;
                    _Sprite.Depth = ArchZBuffers[12];
                    break;
            }

            _Sprite.Pixel = sprite;
            _Sprite.SrcRect = new Microsoft.Xna.Framework.Rectangle(0, 0, _Sprite.Pixel.Width, _Sprite.Pixel.Height);

            return _Sprite;
        }
Пример #10
0
        public void Teste()
        {
                AstarPlanner Planner = new AstarPlanner();

                Planner.Actions.Add(new KillAction());
                Planner.Actions.Add(new BeProtectedAction());
                Planner.Actions.Add(new BeArmedAction());
                Planner.Actions.Add(new GoToAction("lugar0", "lugar1",2));
                Planner.Actions.Add(new GoToAction("lugar1", "lugar2", 2));
                Planner.Actions.Add(new GoToAction("lugar2", "lugar1", 2));
                Planner.Actions.Add(new GoToAction("lugar1", "lugar0", 2));


                WorldState TestWorldState = new WorldState();
                TestWorldState.SetSymbol(new WorldSymbol("Armed", false));
                TestWorldState.SetSymbol(new WorldSymbol("Place", "lugar0"));
                TestWorldState.SetSymbol(new WorldSymbol("Protected", false));
                TestWorldState.SetSymbol(new WorldSymbol("EnemyKilled", false));

                PlanSet PlanSet = Planner.CreatePlan(
                    TestWorldState,
                    new TesteGoal()
                    );

                System.Diagnostics.Debug.Assert(PlanSet != null);
            

        }
Пример #11
0
    public List<AStarNode> GetNeighbours(bool  firstTime)
    {
        List<Action> tempList = new List<Action>();
        WorldState preConditions = new WorldState();

        if(firstTime == true)//returns a list of actions suitable for the goal(a string)
        {
            preConditions = worldState;
        }
        else{
            preConditions = ActionManager.Instance.getAction(this.name).preConditions;
        }

        //go thru postConditions for this action
        //TODO: gör så det funkar för fler postConditions
        /*foreach(KeyValuePair<string, bool> pair in preConditions.getProperties())
        {
            tempList = ActionManager.Instance.getSuitableActions(pair.Key, pair.Value, preConditions);
        }*/

        tempList = ActionManager.Instance.getSuitableActions(preConditions);

        //Debug.Log("templist count: " + tempList.Count);
        foreach(Action action in tempList)
        {
            //Debug.Log("templist name: " + action.actionName);
            AStarNode node = new AStarNode();
            node.name = action.GetActionName();
            node.parent = this;
            node.time = action.time;

            suitableActions.Add(node);
        }
        return suitableActions;
    }
Пример #12
0
 public override bool ProceduralPreConditions(WorldState WorldState)
 {
     foreach (var item in unitsNeeded)
     {
         WorldSymbol WorldSymbol =  WorldState.GetSymbol(item.Key);
         if(WorldSymbol == null || WorldSymbol.GetSymbol<int>() < item.Value)
             return false;
     }
     return true;
 }
Пример #13
0
        public override bool ProceduralPreConditions(WorldState WorldState)
        {
            foreach (var item in resourcesNeeded)
            {
                if (WorldState.GetSymbolValue<int>(item.Key) < item.Value)
                    return false;
            }

            if (WorldState.GetSymbol(HouseNeeded) == null || WorldState.GetSymbolValue<int>(HouseNeeded) == 0)
            {
                return false;
            }

            return true;
        }
Пример #14
0
    public GetBlueAction()
    {
        preConditions = new WorldState();
        preConditions.setProperty("blueResourceIsAvailable", new WorldStateValue(true));

        postConditions = new WorldState();
        postConditions.setProperty("blueResourceIsCollected", new WorldStateValue(true));

        cost = 1.0f;
        time = 4.0f;

        agentTypes = new List<string>();
        agentTypes.Add("Blue");

        this.actionName = "GetBlueAction";
    }
Пример #15
0
    public ScoutRedAction()
    {
        preConditions = new WorldState();
        preConditions.SetProperty("redResourceIsAvailable", new WorldStateValue(false));

        postConditions = new WorldState();
        postConditions.SetProperty("redResourceIsAvailable", new WorldStateValue(true));

        cost = 1.0f;
        time = 4.0f;

        agentTypes = new List<string>();
        agentTypes.Add("Red");

        this.actionName = "ScoutRedAction";
    }
Пример #16
0
    // Use this for initialization
    void Start()
    {
        SpawnPoints = GameObject.FindGameObjectsWithTag("SpawnPosition");
        Player = GameObject.FindGameObjectWithTag("Player");
        Nest = GameObject.FindGameObjectWithTag("Nest");

        FishPrefabs = new string[6];
        FishPrefabs[0] = "TrumpetFish";
        FishPrefabs[1] = "Stupidwels";
        FishPrefabs[2] = "Glotzfisch";
        FishPrefabs[3] = "Krakenkatze";
        FishPrefabs[4] = "Korkenzieherfisch";
        FishPrefabs[5] = "Squarefish";

        State = WorldState.Game;
    }
Пример #17
0
    public BuildBlueFloorAction()
    {
        preConditions = new WorldState();
        preConditions.setProperty("blueResourceIsCollected", new WorldStateValue(true));

        postConditions = new WorldState();
        postConditions.setProperty("blueFloorIsBuilt", new WorldStateValue(true));
        postConditions.setProperty("blueResourceIsCollected", new WorldStateValue(false));

        cost = 1.0f;
        time = 4.0f;

        agentTypes = new List<string>();
        agentTypes.Add("Blue");

        this.actionName = "BuildBlueFloorAction";
    }
Пример #18
0
    public BuildBlueHouseAction()
    {
        preConditions = new WorldState();
        preConditions.SetProperty("blueResourceIsCollected", new WorldStateValue(true, 2));

        postConditions = new WorldState();
        postConditions.SetProperty("blueHouseIsBuilt", new WorldStateValue(true));
        postConditions.SetProperty("blueResourceIsCollected", new WorldStateValue(false));

        cost = 1.0f;
        time = 4.0f;

        agentTypes = new List<string>();
        agentTypes.Add("Blue"); //Only a blue agent can do this action

        this.actionName = "BuildBlueHouseAction";
    }
Пример #19
0
    public ScoutAction()
    {
        preConditions = new WorldState();
        preConditions.setProperty("armedWithGun", new WorldStateValue(true));

        postConditions = new WorldState();
        postConditions.setProperty("enemyVisible", new WorldStateValue(true));

        cost = 4.0f;
        time = 4.0f;

        agentTypes = new List<string>();
        agentTypes.Add("CommanderAgent");
        agentTypes.Add("Builder");

        this.actionName = "ScoutAction";
    }
Пример #20
0
    public ApproachAction()
    {
        preConditions = new WorldState();
        preConditions.setProperty("enemyVisible", new WorldStateValue(true));

        postConditions = new WorldState();
        postConditions.setProperty("nearEnemy", new WorldStateValue(true));

        cost = 3.0f;
        time = 2.0f;

        agentTypes = new List<string>();
        agentTypes.Add("CommanderAgent");
        agentTypes.Add("Builder");

        this.actionName = "ApproachAction";
    }
Пример #21
0
    public WalkAction()
    {
        preConditions = new WorldState();
        preConditions.setProperty("hasDestination", new WorldStateValue(true));

        postConditions = new WorldState();
        postConditions.setProperty("reachedDestination", new WorldStateValue(true));

        cost = 4.0f;
        time = 9.0f;

        agentTypes = new List<string>();
        agentTypes.Add("CommanderAgent");
        agentTypes.Add("Builder");

        this.actionName = "WalkAction";
    }
Пример #22
0
    public GetMagentaAction()
    {
        preConditions = new WorldState();
        preConditions.SetProperty("magentaResourceIsAvailable", new WorldStateValue(true));

        postConditions = new WorldState();
        postConditions.SetProperty("magentaResourceIsCollected", new WorldStateValue(true));

        cost = 1.0f;
        time = 4.0f;

        agentTypes = new List<string>();
        agentTypes.Add("Blue"); //A blue agent or a red agent can do this action
        agentTypes.Add("Red");

        this.actionName = "GetMagentaAction";
    }
Пример #23
0
    public ShootAction()
    {
        preConditions = new WorldState();
        preConditions.setProperty("enemyLinedUp", new WorldStateValue(true));

        postConditions = new WorldState();
        postConditions.setProperty("enemyAlive", new WorldStateValue(false));

        cost = 1.0f;
        time = 2.0f;

        agentTypes = new List<string>();
        agentTypes.Add("CommanderAgent");
        agentTypes.Add("Builder");

        this.actionName = "ShootAction";
    }
Пример #24
0
	public DataStore()
	{
		activeConditions = new Dictionary<string, Condition> ();
		increasingConditions = new List<string> ();

		roomStates = IOManager.LoadRoomStates ();
		playerState = IOManager.LoadPlayerState ();
		worldState = IOManager.LoadWorldState ();
		worldConstants = IOManager.LoadWorldConstants ();

		WorldClock.SetDate (worldState.clock);
		WeatherSystem.SetWeather (worldState.weather);

		foreach(Condition c in playerState.conditions.Values) {
			DataStore.AddCondition (c);
		}
	}
Пример #25
0
    public BuildYellowHouseAction()
    {
        preConditions = new WorldState();
        preConditions.SetProperty("yellowResourceIsCollected", new WorldStateValue(true));

        postConditions = new WorldState();
        postConditions.SetProperty("yellowHouseIsBuilt", new WorldStateValue(true));
        postConditions.SetProperty("yellowResourceIsCollected", new WorldStateValue(false));

        cost = 1.0f;
        time = 4.0f;

        agentTypes = new List<string>();
        agentTypes.Add("Yellow");

        this.actionName = "BuildYellowHouseAction";
    }
Пример #26
0
    public LoadAction()
    {
        preConditions = new WorldState();
        preConditions.setProperty("armedWithGun", new WorldStateValue(true));

        postConditions = new WorldState();
        postConditions.setProperty("weaponLoaded", new WorldStateValue(true));

        cost = 1.0f;
        time = 1.0f;

        agentTypes = new List<string>();
        agentTypes.Add("CommanderAgent");
        agentTypes.Add("Builder");

        this.actionName = "LoadAction";
    }
Пример #27
0
    void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.tag == "Enemy")
        {

            Debug.Log ("ENEMY!!!!");

            WorldState currentWorldState = (WorldState)BlackBoard.Instance.GetFact(clan, "currentWorldState")[0].GetFactValue();

            currentWorldState.setProperty("enemyVisible", new WorldStateValue(true));

            WorldState goalWorldState = new WorldState();
            goalWorldState.setProperty("enemyAlive", new WorldStateValue(false));

            ((Agent)agentComponent).CreateNewPlan(currentWorldState, goalWorldState);

        }
    }
Пример #28
0
    public AimAction()
    {
        preConditions = new WorldState();
        preConditions.setProperty("enemyVisible", new WorldStateValue(true));
        preConditions.setProperty("weaponLoaded", new WorldStateValue(true));

        postConditions = new WorldState();
        postConditions.setProperty("enemyLinedUp", new WorldStateValue(true));

        cost = 1.0f;
        time = 4.0f;

        agentTypes = new List<string>();
        agentTypes.Add("CommanderAgent");
        agentTypes.Add("Builder");

        this.actionName = "AimAction";
    }
Пример #29
0
    public GetStoneAction()
    {
        preConditions = new WorldState();
        preConditions.setProperty("stoneIsAvailable", new WorldStateValue(false));

        postConditions = new WorldState();
        postConditions.setProperty("stoneIsAvailable", new WorldStateValue(true));

        cost = 1.0f;
        time = 4.0f;

        agentTypes = new List<string>();
        agentTypes.Add("Builder");

        this.actionName = "GetStoneAction";

        isShareable = true;
    }
Пример #30
0
        public override void Draw(GraphicsDevice device, WorldState world)
        {
            if(_Dirty){
                if (_Floor == null){
                    _Floor = Content.Get().WorldFloors.Get((ulong)_FloorID);
                    if (_Floor != null)
                    {
                        _Sprite = new _2DSprite
                        {
                            RenderMode = _2DBatchRenderMode.NO_DEPTH
                        };
                    }
                }
                if (_DirtyTexture && _Floor != null){
                    SPR2 sprite = null;
                    switch(world.Zoom){
                        case WorldZoom.Far:
                            sprite = _Floor.Far;
                            _Sprite.DestRect = DESTINATION_FAR;
                            break;
                        case WorldZoom.Medium:
                            sprite = _Floor.Medium;
                            _Sprite.DestRect = DESTINATION_MED;
                            break;
                        case WorldZoom.Near:
                            sprite = _Floor.Near;
                            _Sprite.DestRect = DESTINATION_NEAR;
                            break;
                    }
                    if (world.Rotation == WorldRotation.TopRight || world.Rotation == WorldRotation.BottomRight) _Sprite.FlipVertically = true;
                    if ((int)world.Rotation > 1) _Sprite.FlipHorizontally = true; //todo - find out why these don't work (really it is a mystery)

                    _Sprite.Pixel = world._2D.GetTexture(sprite.Frames[0]);
                    _Sprite.SrcRect = new Microsoft.Xna.Framework.Rectangle(0, 0, _Sprite.Pixel.Width, _Sprite.Pixel.Height);
                }

                _DirtyTexture = false;
                _Dirty = false;
            }

            if (_Sprite != null){
                world._2D.Draw(_Sprite);
            }
        }
Пример #31
0
 public void StartFighting()
 {
     state = WorldState.CHARGING;
     gameObject.SetActive(true);
     fillImage.fillAmount = currentBossBar / maxBossBar;
 }
Пример #32
0
        public override void Draw(GraphicsDevice device, WorldState world)
        {
            var pos = Position;

            Avatar.Position = WorldSpace.GetWorldFromTile(pos);
            if (Avatar.Skeleton == null)
            {
                return;
            }
            var headpos   = Avatar.Skeleton.GetBone("HEAD").AbsolutePosition / 3.0f;
            var tHead1    = Vector3.Transform(new Vector3(headpos.X, headpos.Z, headpos.Y), Matrix.CreateRotationZ((float)(RadianDirection + Math.PI)));
            var transhead = tHead1 + pos - new Vector3(0.5f, 0.5f, 0f);

            if (!Visible)
            {
                return;
            }

            if (Avatar != null)
            {
                Color col = Color.White;
                if ((DisplayFlags & AvatarDisplayFlags.ShowAsGhost) > 0)
                {
                    col = new Color(32, 255, 96) * 0.66f;
                }
                else if (IsDead)
                {
                    col = new Color(255, 255, 255, 64);
                }

                Avatar.LightPositions = (WorldConfig.Current.AdvancedLighting)?CloseLightPositions(Position):null;
                var newWorld = Matrix.CreateRotationY((float)(Math.PI - RadianDirection)) * this.World;
                if (Scale != 1f)
                {
                    newWorld = Matrix.CreateScale(Scale) * newWorld;
                }
                DrawAvatarMesh(device, world, newWorld, col);
                //world._3D.DrawMesh(newWorld, Avatar, (short)ObjectID, (Room>65530 || Room == 0)?Room:blueprint.Rooms[Room].Base, col, ALevel);
            }

            if (Headline != null && !Headline.IsDisposed)
            {
                var lastCull  = device.RasterizerState;
                var lastBlend = device.BlendState;
                device.RasterizerState = RasterizerState.CullNone;
                device.BlendState      = BlendState.NonPremultiplied;
                var headOff = (transhead - Position) + new Vector3(0, 0, 0.66f);
                if (!world.Cameras.Safe2D)
                {
                    //DrawHeadline3D(device, world);
                }
                else
                {
                    var headPx = world.WorldSpace.GetScreenFromTile(headOff);

                    if (HeadlineSprite == null)
                    {
                        HeadlineSprite = new _2DStandaloneSprite();
                    }
                    HeadlineSprite.Pixel = Headline;
                    HeadlineSprite.Depth = TextureGenerator.GetWallZBuffer(device)[30];

                    HeadlineSprite.SrcRect       = new Rectangle(0, 0, Headline.Width, Headline.Height);
                    HeadlineSprite.WorldPosition = headOff;
                    var off = PosCenterOffsets[(int)world.Zoom - 1];
                    HeadlineSprite.DestRect = new Rectangle(
                        ((int)headPx.X - Headline.Width / 2) + (int)off.X,
                        ((int)headPx.Y - Headline.Height / 2) + (int)off.Y, Headline.Width, Headline.Height);

                    HeadlineSprite.AbsoluteDestRect = HeadlineSprite.DestRect;
                    HeadlineSprite.AbsoluteDestRect.Offset(world.WorldSpace.GetScreenFromTile(pos));
                    HeadlineSprite.AbsoluteWorldPosition = HeadlineSprite.WorldPosition + WorldSpace.GetWorldFromTile(pos);

                    HeadlineSprite.Room = Room;
                    HeadlineSprite.PrepareVertices(device);
                    world._2D.EnsureIndices();
                    world._2D.DrawImmediate(HeadlineSprite);
                }
                device.RasterizerState = lastCull;
                device.BlendState      = lastBlend;
            }
        }
Пример #33
0
 static void s_InitializationMessage(object sender, InitializationMessageEventArgs ime)
 {
     ws = new WorldState(ime.message);
     rc = new StupidController(ws, s);
 }
Пример #34
0
 public void ApplyWorldState(WorldState ws)
 {
 }
Пример #35
0
 public void ApplyWorldState(WorldState ws)
 {
     //throw new NotImplementedException();
 }
Пример #36
0
 /// <summary>
 /// Executes the action.
 /// </summary>
 public void Execute()
 {
     _previousWorldState      = Mode.Instance.WorldState;
     _previousItemPlacement   = Mode.Instance.ItemPlacement;
     Mode.Instance.WorldState = _worldState;
 }
Пример #37
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="worldState">
 /// The new world state setting.
 /// </param>
 public ChangeWorldState(WorldState worldState)
 {
     _worldState = worldState;
 }
Пример #38
0
 public override void Initialize(GraphicsDevice device, WorldState world)
 {
     base.Initialize(device, world);
     Avatar.StoreOnGPU(device);
 }
Пример #39
0
        public void ValidateSprite(WorldState world)
        {
            if (DrawGroup == null)
            {
                return;
            }
            if (_Dirty)
            {
                if (_TextureDirty)
                {
                    Items.Clear();
                    var direction = (uint)_Direction;

                    /** Compute the direction **/
                    var image = DrawGroup.GetImage(direction, (uint)world.Zoom, (uint)world.Rotation);
                    if (image != null)
                    {
                        foreach (var sprite in image.Sprites)
                        {
                            if (sprite == null)
                            {
                                continue;
                            }
                            var texture = world._2D.GetWorldTexture(sprite);
                            if (texture == null || texture.ZBuffer == null)
                            {
                                continue;
                            }

                            var isDynamic = sprite.SpriteID >= DynamicSpriteBaseID && sprite.SpriteID < (DynamicSpriteBaseID + NumDynamicSprites);
                            if (isDynamic)
                            {
                                var dynamicIndex = (ushort)(sprite.SpriteID - DynamicSpriteBaseID);

                                var isVisible = (dynamicIndex > 63) ? ((DynamicSpriteFlags2 & ((ulong)0x1 << (dynamicIndex - 64))) > 0):
                                                ((DynamicSpriteFlags & ((ulong)0x1 << dynamicIndex)) > 0);
                                if (!isVisible)
                                {
                                    continue;
                                }
                            }
                            var item = new _2DSprite(); //do not use sprite pool for DGRP, since we can reliably remember our own sprites.
                            item.Pixel = texture.Pixel;
                            item.Depth = texture.ZBuffer;
                            if (texture.ZBuffer != null)
                            {
                                item.RenderMode    = _2DBatchRenderMode.Z_BUFFER;
                                item.WorldPosition = sprite.ObjectOffset;
                            }
                            else
                            {
                                item.RenderMode = _2DBatchRenderMode.NO_DEPTH;
                            }

                            item.SrcRect          = new Rectangle(0, 0, item.Pixel.Width, item.Pixel.Height);
                            item.DestRect         = new Rectangle(0, 0, item.Pixel.Width, item.Pixel.Height);
                            item.FlipHorizontally = sprite.Flip;

                            Items.Add(new DGRPRendererItem {
                                Sprite = item, DGRPSprite = sprite
                            });
                        }
                    }

                    _TextureDirty = false;
                }

                int maxX = int.MinValue, maxY = int.MinValue;
                int minX = int.MaxValue, minY = int.MaxValue;
                foreach (var item in Items)
                {
                    var sprite     = item.Sprite;
                    var dgrpSprite = item.DGRPSprite;

                    var pxX = (world.WorldSpace.CadgeWidth / 2.0f) + dgrpSprite.SpriteOffset.X;
                    var pxY = (world.WorldSpace.CadgeBaseLine - sprite.Pixel.Height) + dgrpSprite.SpriteOffset.Y;

                    if (dgrpSprite.ObjectOffset != Vector3.Zero)
                    {
                    }
                    var centerRelative = dgrpSprite.ObjectOffset * new Vector3(1f / 16f, 1f / 16f, 1f / 5f);
                    centerRelative = Vector3.Transform(centerRelative, Matrix.CreateRotationZ(RadianDirection));

                    var pxOff = world.WorldSpace.GetScreenFromTile(centerRelative);

                    sprite.DestRect.X = (int)(pxX + pxOff.X);
                    sprite.DestRect.Y = (int)(pxY + pxOff.Y);

                    if (sprite.DestRect.X < minX)
                    {
                        minX = sprite.DestRect.X;
                    }
                    if (sprite.DestRect.Y < minY)
                    {
                        minY = sprite.DestRect.Y;
                    }
                    if (sprite.DestRect.X + sprite.Pixel.Width > maxX)
                    {
                        maxX = sprite.DestRect.X + sprite.Pixel.Width;
                    }
                    if (sprite.DestRect.Y + sprite.Pixel.Height > maxY)
                    {
                        maxY = sprite.DestRect.Y + sprite.Pixel.Height;
                    }

                    sprite.WorldPosition = centerRelative * 3f;
                    var y = sprite.WorldPosition.Z;
                    sprite.WorldPosition.Z = sprite.WorldPosition.Y;
                    sprite.WorldPosition.Y = y;
                    sprite.Room            = ((dgrpSprite.Flags & DGRPSpriteFlags.Luminous) > 0 && Room != 65534 && Room != 65533)?(ushort)65535:Room;
                    sprite.Floor           = Level;
                }
                Bounding = new Rectangle(minX, minY, maxX - minX, maxY - minY);

                _Dirty = false;
            }
        }
Пример #40
0
        public void DrawFloor(GraphicsDevice gd, Effect e, WorldZoom zoom, WorldRotation rot, List <Texture2D> roommaps, HashSet <sbyte> floors, EffectPass pass,
                              Matrix?lightWorld = null, WorldState state = null, int minFloor = 0)
        {
            //assumes the effect and all its parameters have been set up already
            //we just need to get the right texture and offset
            var flrContent = Content.GameContent.Get.WorldFloors;

            e.Parameters["TexOffset"].SetValue(new Vector2());// TexOffset[zoom]*-1f);
            var tmat = TexMat[rot];

            e.Parameters["TexMatrix"].SetValue(tmat);

            var f = 0;

            foreach (var floor in Floors)
            {
                if (!floors.Contains((sbyte)(f++)))
                {
                    continue;
                }

                Matrix worldmat;
                if (lightWorld == null)
                {
                    worldmat = Matrix.CreateTranslation(0, 2.95f * (f - 1) * 3 - Bp.BaseAlt * Bp.TerrainFactor * 3, 0);
                }
                else
                {
                    worldmat = Matrix.CreateScale(1, 0, 1) * Matrix.CreateTranslation(0, 1f * (f - (1 + minFloor)), 0) * lightWorld.Value;
                    e.Parameters["DiffuseColor"].SetValue(new Vector4(1, 1, 1, 1) * (float)(6 - (f - (minFloor))) / 5f);
                }

                e.Parameters["World"].SetValue(worldmat);
                e.Parameters["Level"].SetValue((float)(f - ((lightWorld == null)?0.999f:1f)));
                if (roommaps != null)
                {
                    e.Parameters["RoomMap"].SetValue(roommaps[f - 1]);
                }
                foreach (var type in floor.GroupForTileType)
                {
                    bool water = false;
                    var  dat   = type.Value.GPUData;
                    if (dat == null)
                    {
                        continue;
                    }
                    gd.Indices = dat;

                    var       id         = type.Key;
                    var       doubleDraw = false;
                    Texture2D SPR        = null;

                    if (id == 0)
                    {
                        e.Parameters["UseTexture"].SetValue(false);
                        e.Parameters["IgnoreColor"].SetValue(false);
                    }
                    else
                    {
                        if (id >= 65503)
                        {
                            if (id == 65503)
                            {
                                water = true;
                                var airTiles = TextureGenerator.GetAirTiles(gd);
                                switch (zoom)
                                {
                                case WorldZoom.Far:
                                    SPR = airTiles[2];
                                    break;

                                case WorldZoom.Medium:
                                    SPR = airTiles[1];
                                    break;

                                case WorldZoom.Near:
                                    SPR = airTiles[0];
                                    break;
                                }
                            }
                            else
                            {
                                e.Parameters["Water"].SetValue(true);
                                var pool = id >= 65520;
                                water = true;
                                if (!pool)
                                {
                                    e.Parameters["UseTexture"].SetValue(false);
                                    e.Parameters["IgnoreColor"].SetValue(false);

                                    //quickly draw under the water
                                    pass.Apply();
                                    gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, type.Value.GeomForOffset.Count * 2);

                                    e.Parameters["UseTexture"].SetValue(true);
                                    e.Parameters["IgnoreColor"].SetValue(true);
                                    if (lightWorld == null)
                                    {
                                        e.Parameters["World"].SetValue(worldmat * Matrix.CreateTranslation(0, 0.05f, 0));
                                    }
                                    id -= 65504;
                                }
                                else
                                {
                                    id -= 65520;
                                }

                                e.Parameters["TexMatrix"].SetValue(CounterTexMat[rot]);

                                var roti = (int)rot;
                                roti = (4 - roti) % 4;
                                id   = (ushort)(((id << roti) & 15) | (id >> (4 - roti)));
                                //pools & water are drawn with special logic, and may also be drawn slightly above the ground.

                                int baseSPR;
                                int frameNum = 0;
                                if (state != null)
                                {
                                    switch (zoom)
                                    {
                                    case WorldZoom.Far:
                                        baseSPR  = (pool) ? 0x400 : 0x800;
                                        frameNum = (pool) ? 0 : 2;
                                        SPR      = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]);
                                        break;

                                    case WorldZoom.Medium:
                                        baseSPR  = (pool) ? 0x410 : 0x800;
                                        frameNum = (pool) ? 0 : 1;
                                        SPR      = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]);
                                        break;

                                    default:
                                        baseSPR = (pool) ? 0x420 : 0x800;
                                        SPR     = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]);
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            var flr = flrContent.Get(id);

                            if (flr == null)
                            {
                                continue;
                            }

                            if (state != null)
                            {
                                switch (zoom)
                                {
                                case WorldZoom.Far:
                                    SPR = state._2D.GetTexture(flr.Far.Frames[0]);
                                    break;

                                case WorldZoom.Medium:
                                    SPR = state._2D.GetTexture(flr.Medium.Frames[0]);
                                    break;

                                default:
                                    SPR = state._2D.GetTexture(flr.Near.Frames[0]);
                                    break;
                                }
                            }
                        }

                        //e.Parameters["UseTexture"].SetValue(SPR != null);
                    }

                    e.Parameters["BaseTex"].SetValue(SPR);
                    if (SPR != null && SPR.Name == null)
                    {
                        doubleDraw = true;
                        SPR.Name   = Alt.ToString();
                    }
                    pass.Apply();
                    if (Alt && !FSOEnvironment.DirectX)
                    {
                        //opengl bug workaround. For some reason, the texture is set to clamp mode by some outside force on first draw.
                        //Monogame then thinks the texture is wrapping.
                        gd.SamplerStates[1] = CustomWrap;
                    }
                    gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, type.Value.GeomForOffset.Count * 2);
                    //gd.SamplerStates[1] = SamplerState.LinearWrap;

                    if (id == 0)
                    {
                        e.Parameters["UseTexture"].SetValue(true);
                        e.Parameters["IgnoreColor"].SetValue(true);
                    }
                    if (water)
                    {
                        e.Parameters["World"].SetValue(worldmat);
                        e.Parameters["TexMatrix"].SetValue(tmat);
                        e.Parameters["Water"].SetValue(false);
                    }
                }
            }
            e.Parameters["Water"].SetValue(false);
            Alt = !Alt;
        }
Пример #41
0
 public abstract bool TryPerformAction(WorldState worldState, Directions agentDir, Directions boxDir);
Пример #42
0
 public Player(WorldState world, Player player) : this(world, player.Name)
 {
     _activeQuests = player._activeQuests;
 }
Пример #43
0
 public TempEntity(WorldState ws, ServerClass sClass, SendTable table)
 {
     World        = ws;
     Class        = sClass;
     NetworkTable = table;
 }
Пример #44
0
        /// <summary>
        /// Prep work before screen is painted
        /// </summary>
        /// <param name="gd"></param>
        /// <param name="state"></param>
        public override void PreDraw(GraphicsDevice gd, WorldState state)
        {
            if (Blueprint == null)
            {
                return;
            }
            Blueprint.Terrain.SubworldOff = GlobalPosition * 3;
            var damage   = Blueprint.Damage;
            var oldLevel = state.Level;
            var oldBuild = state.BuildMode;

            state.SilentLevel     = State.Level;
            state.SilentBuildMode = 0;

            /**
             * This is a little bit different from a normal 2d world. All objects are part of the static
             * buffer, and they are redrawn into the parent world's scroll buffers.
             */

            var recacheWalls   = false;
            var recacheObjects = false;

            foreach (var item in damage)
            {
                switch (item.Type)
                {
                case BlueprintDamageType.ROTATE:
                case BlueprintDamageType.ZOOM:
                case BlueprintDamageType.LEVEL_CHANGED:
                    recacheObjects = true;
                    recacheWalls   = true;
                    break;

                case BlueprintDamageType.SCROLL:
                    break;

                case BlueprintDamageType.LIGHTING_CHANGED:
                    break;

                case BlueprintDamageType.OBJECT_MOVE:
                case BlueprintDamageType.OBJECT_GRAPHIC_CHANGE:
                case BlueprintDamageType.OBJECT_RETURN_TO_STATIC:
                    recacheObjects = true;
                    break;

                case BlueprintDamageType.WALL_CUT_CHANGED:
                case BlueprintDamageType.FLOOR_CHANGED:
                case BlueprintDamageType.WALL_CHANGED:
                    recacheWalls = true;
                    break;
                }
            }
            damage.Clear();

            var is2d = state.Camera is WorldCamera;

            if (is2d)
            {
                state._2D.End();
                state._2D.Begin(state.Camera);
            }
            if (recacheWalls)
            {
                //clear the sprite buffer before we begin drawing what we're going to cache
                Blueprint.Terrain.RegenTerrain(gd, Blueprint);
                Blueprint.FloorGeom.FullReset(gd, false);
                Blueprint.WCRC.Generate(gd, state, false);
            }

            state.SilentBuildMode = oldBuild;
            state.SilentLevel     = oldLevel;
        }
Пример #45
0
 public double GetPriority(int playerIndex, WorldState worldState)
 {
     throw new NotImplementedException();
 }
Пример #46
0
 public abstract bool IsSatisfied(WorldState worldState);
Пример #47
0
 // Change State
 public void ChangeState(WorldState state)
 {
     Debug.Log("index: " + charIndex + " ChangeState: " + state);
     worldState = state;
     NotifyObservers(state);
 }
Пример #48
0
 public void BuildPlan(GOAPActionType[] candidates, WorldState curWS)
 {
     Plan.Build(candidates, curWS, this);
 }
Пример #49
0
        public bool Work()
        {
            // Hack
            if (m_worldThread == null)
            {
                m_worldThread = Thread.CurrentThread;
            }

            VerifyAccess();

            bool again = true;

            if (m_state == WorldState.Idle)
            {
                m_livings.Process();

                if (m_okToStartTick)
                {
                    StartTick();
                }
                else
                {
                    again = false;
                }
            }

            if (m_state == WorldState.TickOngoing)
            {
                if (this.TickMethod == WorldTickMethod.Simultaneous)
                {
                    again = SimultaneousWork();
                }
                else if (this.TickMethod == WorldTickMethod.Sequential)
                {
                    again = SequentialWork();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            if (m_state == WorldState.TickDone)
            {
                EndTick();
            }

            // XXX keep world writable for now
            //this.IsWritable = false;

            // no point in entering read lock here, as this thread is the only one that can get a write lock

            if (WorkEnded != null)
            {
                WorkEnded();
            }

            if (m_state == WorldState.TickEnded)
            {
                m_state = WorldState.Idle;
            }

            return(again);
        }
Пример #50
0
 public bool UpdateGoal(WorldState curWS)
 {
     return(Plan.UpdatePlan(curWS));
 }
Пример #51
0
 public void Play()
 {
     _world      = new PlayingWorld(this);
     _worldState = WorldState.Playing;
 }
Пример #52
0
 public override void SetWSSatisfactionForPlanning(WorldState worldState)
 {
     worldState.SetWSProperty(E_PropKey.E_ATTACK_TARGET, false);
 }
Пример #53
0
 public override void Update(GraphicsDevice device, WorldState world)
 {
     base.Update(device, world);
 }
Пример #54
0
 static void Postfix(StaffMenu __instance, StaffDefinition.Type staffType, StaffMenu.StaffMenuSettings ____staffMenuSettings, WorldState ____worldState, List <JobDescription>[] ____jobs, CharacterManager ____characterManager)
 {
     if (!Main.enabled)
     {
         return;
     }
     try
     {
         int num = 0;
         foreach (object obj in ____staffMenuSettings.JobsListContainer)
         {
             Transform      transform = (Transform)obj;
             JobDescription job       = ____jobs[(int)staffType][num];
             TMP_Text       component = UnityEngine.Object.Instantiate <GameObject>(____staffMenuSettings.TitleText.gameObject).GetComponent <TMP_Text>();
             component.rectTransform.SetParent(transform);
             int staffCount = ____characterManager.StaffMembers.Count((Staff s) => !s.HasResigned() && !s.HasBeenFired() && job.IsSuitable(s) && !s.JobExclusions.Contains(job));
             int roomCount  = 0;
             if (job is JobRoomDescription)
             {
                 roomCount      = ____worldState.AllRooms.Count((Room x) => x.Definition == ((JobRoomDescription)job).Room);
                 component.text = staffCount.ToString() + "/" + roomCount.ToString();
                 StaffJobIcon[] componentsInChildren = ____staffMenuSettings.JobsListContainer.gameObject.GetComponentsInChildren <StaffJobIcon>();
                 if (componentsInChildren != null && num < componentsInChildren.Length)
                 {
                     componentsInChildren[num].Tooltip.SetDataProvider(delegate(Tooltip tooltip)
                     {
                         tooltip.Text = string.Concat(new string[]
                         {
                             job.GetJobAssignmentTooltipString(),
                             "\n\nSatff Assigned: ",
                             staffCount.ToString(),
                             "\nRooms Built: ",
                             roomCount.ToString()
                         });
                     });
                 }
             }
             else if (job is JobItemDescription)
             {
                 component.text = staffCount.ToString();
                 StaffJobIcon[] componentsInChildren2 = ____staffMenuSettings.JobsListContainer.gameObject.GetComponentsInChildren <StaffJobIcon>();
                 if (componentsInChildren2 != null && num < componentsInChildren2.Length)
                 {
                     componentsInChildren2[num].Tooltip.SetDataProvider(delegate(Tooltip tooltip)
                     {
                         tooltip.Text = job.GetJobAssignmentTooltipString() + "\n\nSatff Assigned: " + staffCount.ToString();
                     });
                 }
             }
             else if (job is JobMaintenanceDescription)
             {
                 string text      = staffCount.ToString();
                 int    itemCount = (from mj in ____worldState.GetRoomItemsWithMaintenanceDescription(((JobMaintenanceDescription)job).Description)
                                     where mj.Definition.Interactions.Count((InteractionDefinition inter) => inter.Type == InteractionAttributeModifier.Type.Maintain) > 0
                                     select mj).Count <RoomItem>();
                 text           = text + "/" + itemCount.ToString();
                 component.text = text;
                 StaffJobIcon[] componentsInChildren3 = ____staffMenuSettings.JobsListContainer.gameObject.GetComponentsInChildren <StaffJobIcon>();
                 if (componentsInChildren3 != null && num < componentsInChildren3.Length)
                 {
                     componentsInChildren3[num].Tooltip.SetDataProvider(delegate(Tooltip tooltip)
                     {
                         tooltip.Text = string.Concat(new string[]
                         {
                             job.GetJobAssignmentTooltipString(),
                             "\n\nSatff Assigned: ",
                             staffCount.ToString(),
                             "\nMaintenance Items: ",
                             itemCount.ToString()
                         });
                     });
                 }
             }
             else if (job is JobUpgradeDescription)
             {
                 int    upgradeCount       = 0;
                 string machinesForUpgarde = "";
                 foreach (Room room in ____worldState.AllRooms)
                 {
                     foreach (RoomItem roomItem in room.FloorPlan.Items)
                     {
                         RoomItemUpgradeDefinition nextUpgrade = roomItem.Definition.GetNextUpgrade(roomItem.UpgradeLevel);
                         if (nextUpgrade != null && roomItem.Level.Metagame.HasUnlocked(nextUpgrade) && roomItem.GetComponent <RoomItemUpgradeComponent>() == null)
                         {
                             upgradeCount++;
                             machinesForUpgarde = machinesForUpgarde + "\n" + roomItem.Name;
                         }
                     }
                 }
                 if (!string.IsNullOrEmpty(machinesForUpgarde))
                 {
                     StaffJobIcon[] componentsInChildren4 = ____staffMenuSettings.JobsListContainer.gameObject.GetComponentsInChildren <StaffJobIcon>();
                     if (componentsInChildren4 != null && num < componentsInChildren4.Length)
                     {
                         componentsInChildren4[num].Tooltip.SetDataProvider(delegate(Tooltip tooltip)
                         {
                             tooltip.Text = string.Concat(new string[]
                             {
                                 job.GetJobAssignmentTooltipString(),
                                 "\n\nSatff Assigned: ",
                                 staffCount.ToString(),
                                 "\n",
                                 machinesForUpgarde
                             });
                         });
                     }
                 }
                 component.text = staffCount.ToString() + "/" + upgradeCount;
             }
             else
             {
                 if (!(job is JobGhostDescription) && !(job is JobFireDescription))
                 {
                     continue;
                 }
                 component.text = staffCount.ToString();
             }
             component.enableAutoSizing   = false;
             component.fontSize           = 18f;
             component.enableWordWrapping = false;
             component.overflowMode       = 0;
             component.alignment          = TextAlignmentOptions.Midline;
             component.color                          = Color.white;
             component.outlineColor                   = Color.black;
             component.outlineWidth                   = 1f;
             component.rectTransform.anchorMin        = new Vector2(0.5f, 0f);
             component.rectTransform.anchorMax        = new Vector2(0.5f, 1f);
             component.rectTransform.anchoredPosition = new Vector2(0f, -15f);
             component.rectTransform.sizeDelta        = transform.GetComponent <RectTransform>().sizeDelta;
             num++;
         }
     }
     catch (Exception ex)
     {
         Main.Logger.Error(ex.ToString() + ": " + ex.StackTrace.ToString());
     }
 }
Пример #55
0
 public override void Preload(GraphicsDevice device, WorldState world)
 {
     //nothing important to do here
 }
Пример #56
0
    private void Update()
    {
        switch (state)
        {
        case WorldState.IDLE:

            break;

        case WorldState.CHARGING:

            if (currentBossBar >= maxBossBar)
            {
                fillImage.fillAmount = 1;
                GoToBossState();
            }
            else
            {
                currentBossBar      -= bossBarDecreasePerSecond * Time.deltaTime;
                currentBossBar       = Mathf.Max(0, currentBossBar);
                fillImage.fillAmount = currentBossBar / maxBossBar;
            }

            break;

        case WorldState.BOSS:


            if (boss == null || boss.HP <= 0)
            {
                word.words = "CLAIM THE CROWN";
                word.CreateWord();
                state = WorldState.ENDSTATE;
                fillImage.fillAmount = 0;



                foreach (Unit g in UnityEngine.Object.FindObjectsOfType <Unit>())
                {
                    if (g is ItemManager)
                    {
                    }
                    else
                    {
                        Destroy(g.gameObject);
                    }
                }

                EnemySpawner.instance.StopAllCoroutines();
                PickupAndItemSpawner.instance.StopAllCoroutines();

                crown.gameObject.SetActive(true);
            }
            else
            {
                if (Time.time > lastHeal)
                {
                    boss.HP++;
                    if (boss.HP > boss.MaxHP)
                    {
                        boss.HP = boss.MaxHP;
                    }
                    lastHeal = Time.time + healInterval;
                }


                fillImage.fillAmount = (float)boss.HP / (float)boss.MaxHP;
            }

            break;

        case WorldState.ENDSTATE:

            break;
        }
    }
Пример #57
0
    public virtual void Build(GOAPActionType[] candidates, WorldState curWS, GOAPGoal goal)
    {
        _actions.Clear();

        // 测试用,后续改成A*

        /*foreach (var actionType in candidates)
         * {
         *  GOAPAction action = GOAPActionFactory.Get(actionType, _agent);
         *  if (action == null)
         *  {
         *      Debug.LogWarning("null for actiontype: " + actionType);
         *      continue;
         *  }
         *  if (actionType == GOAPActionType.GOTO_MELEE_RANGE)
         *  {
         *      _actions.Enqueue(action);
         *  }
         * }*/
        GOAPAction action = null;

        switch (goal.GoalType)
        {
        case GOAPGoalType.STEP_IN:
            action = GOAPActionFactory.Get(GOAPActionType.STEP_IN, _owner);
            _actions.Enqueue(action);
            break;

        case GOAPGoalType.STEP_OUT:
            action = GOAPActionFactory.Get(GOAPActionType.STEP_OUT, _owner);
            _actions.Enqueue(action);
            break;

        case GOAPGoalType.STEP_AROUND:
            action = GOAPActionFactory.Get(GOAPActionType.STEP_AROUND, _owner);
            _actions.Enqueue(action);
            break;

        case GOAPGoalType.ATTACK_TARGET:
            action = GOAPActionFactory.Get(GOAPActionType.GOTO_MELEE_RANGE, _owner);
            _actions.Enqueue(action);
            if (_owner.agentType == AgentType.PEASANT || _owner.agentType == AgentType.SWORD_MAN)
            {
                action = GOAPActionFactory.Get(GOAPActionType.ATTACK_MELEE_ONCE, _owner);
                _actions.Enqueue(action);
            }
            else if (_owner.agentType == AgentType.DOUBLE_SWORDS_MAN)
            {
                if (UnityEngine.Random.Range(0, 2) == 0)
                {
                    action = GOAPActionFactory.Get(GOAPActionType.ATTACK_MELEE_TWO_SWORDS, _owner);
                }
                else
                {
                    action = GOAPActionFactory.Get(GOAPActionType.ATTACK_WHIRL, _owner);
                }
                _actions.Enqueue(action);
            }
            break;

        case GOAPGoalType.REACT_TO_DAMAGE:
            if (curWS.GetWSProperty(WorldStatePropKey.EVENT).GetEvent() == EventTypes.HIT)
            {
                action = GOAPActionFactory.Get(GOAPActionType.INJURY, _owner);
                _actions.Enqueue(action);
            }
            else if (curWS.GetWSProperty(WorldStatePropKey.EVENT).GetEvent() == EventTypes.DEAD)
            {
                action = GOAPActionFactory.Get(GOAPActionType.DEATH, _owner);
                _actions.Enqueue(action);
            }
            else if (curWS.GetWSProperty(WorldStatePropKey.EVENT).GetEvent() == EventTypes.KNOCKDOWN)
            {
                action = GOAPActionFactory.Get(GOAPActionType.KNOCKDOWN, _owner);
                _actions.Enqueue(action);
            }
            break;

        case GOAPGoalType.BLOCK:
            action = GOAPActionFactory.Get(GOAPActionType.BLOCK, _owner);
            _actions.Enqueue(action);
            break;

        default:
            break;
        }

        if (_actions.Count > 0)
        {
            _actions.Peek().Activate();
        }
    }
Пример #58
0
 public override void SetWSSatisfactionForPlanning(WorldState worldState)
 {
     worldState.SetWSProperty(E_PropKey.UseWorldObject, false);
 }
Пример #59
0
 public _3DWorldBatch(WorldState state)
 {
     this.State = state;
     //this.Effect = new BasicEffect(state.Device);
 }
Пример #60
0
 public bool IsSatisfied(WorldState goal)
 {
     return(goal.GetUnsatisfiedCount(this) == 0);
 }