Beispiel #1
0
    public override void Update()
    {
        base.Update();

        // Someone else took the jam?
        if (Workstation.Jams == 0 && NPC.Jams == 0)
        {
            Finish();
        }

        if (NPC.Jams == 0)
        {
            // Pickup jam if reached
            if (NPC.CurrentPos == BuildableArea.GetCellFromPosition(Workstation.PickupZone))
            {
                NPC.SetTargetCell(BuildableArea.GetCellFromPosition(SellBox.Instance.DropZone));

                NPC.Jams = 1;
                NPC.PickupItem(Workstation.JamsParent.GetChild(Workstation.Jams - 1).gameObject);
                Workstation.AddJam(-1);
            }
        }
        else
        {
            if (NPC.CurrentPos == BuildableArea.GetCellFromPosition(SellBox.Instance.DropZone))
            {
                SellBox.Instance.SellJam(NPC.Jams);
                NPC.Jams = 0;
                NPC.DropItem();
                NPC.TaskComplete();

                Finish();
            }
        }
    }
    public override void Update()
    {
        base.Update();

        // Cook if reached
        if (NPC.CurrentPos == BuildableArea.GetCellFromPosition(Workstation.CookZone))
        {
            NPC.SetTargetCell(NPC.CurrentPos);               // Safety, left over from bad debug
            if (Workstation.Cook())
            {
                // Try to finish after each batch, but if wants to do more then may just be reassigned
                Workstation.AssignedNPC = null;
                Finish();

                NPC.TaskComplete();
            }
        }

        // Don't stand around if nothing can be made
        if (Workstation.Berries < Workstation.BERRIES_TO_JAM || Workstation.Jams >= Workstation.MAX_JAMS)
        {
            Workstation.AssignedNPC = null;
            Finish();
        }
    }
    public void StartParty()
    {
        if (IsParty)
        {
            return;                    // In case hold F11
        }
        IsParty = true;

        // Enable party prefab
        transform.Find("PartyMode").gameObject.SetActive(true);

        // Show dialogue popup
        SceneController.Instance.SummonDialogueBubble("Wow! All your friends threw you a surprise party to say thank you!! Click e on them to talk and catch up with what they've been up to!");

        // Readd all npcs
        foreach (var npc in transform.GetComponentsInChildren <NPC_Commune>(true))
        {
            npc.gameObject.SetActive(true);
            npc.SetPos(BuildableArea.GetCellFromPosition(Player_Commune.Instance.transform.position));
            npc.FindJob();
            npc.SetParty();
        }

        // Set to night time
        FindObjectOfType <Camera>().backgroundColor = new Color(0.2f, 0.2f, 0.2f, 1);
        FindObjectOfType <Light>().intensity        = 0.2f;
        foreach (var sprite in FindObjectsOfType <SpriteRenderer>())
        {
            sprite.color = sprite.color * Color.gray;
        }
    }
Beispiel #4
0
    public override void Update()
    {
        base.Update();

        // Path to player but stop when one square away
        int dist = Mathf.Abs(NPC.CurrentPos.x - TargetPos.x) + Mathf.Abs(NPC.CurrentPos.y - TargetPos.y);

        if (dist <= 2)
        {
            // Stop moving
            NPC.SetTargetCell(NPC.CurrentPos);

            // Open dialogue
            // Mark story as told at this point
            NPC.TalkToPlayer();

            Finish();
        }
        else
        {
            // Continuously find player pos
            TargetPos = BuildableArea.GetCellFromPosition(Player_Commune.Instance.transform.position);
            NPC.SetIfNotTargetCell(TargetPos);
        }
    }
Beispiel #5
0
    protected void FindWorkstation()
    {
        // Find workstation with space for berries (lowest?)
        // TODO prioritise top up of currently worked stations?
        foreach (var workstation in GameObject.FindObjectsOfType <Workstation>())
        {
            if (workstation.Berries < Workstation.MAX_BERRIES)
            {
                DropOff = workstation;
                break;
            }
        }

        if (DropOff != null)
        {
            NPC.SetTargetCell(BuildableArea.GetCellFromPosition(DropOff.DropZone));
            // If find then set duration back to 0
            Duration = 0;
        }
        else
        {
            // If don't find one then set duration timeout, but still search every update
            if (Duration == 0)
            {
                StartTime = Time.time;
                Duration  = 5;                // TODO make this clearer variable
            }
        }

        // At end of timeout any fruit is destroyed
        // TODO If it takes too long drop berries in sell bin?
        // TODO Or just eat it?
    }
Beispiel #6
0
    void Start()
    {
        // Ensure data grid is filled properly (in case added in editor)
        var cell = BuildableArea.GetCellFromPosition(gameObject);

        BuildableArea.Instance.Grid.nodes[cell.x, cell.y].Type     = NesScripts.Controls.PathFind.NodeContent.Impasse;
        BuildableArea.Instance.Grid.nodes[cell.x, cell.y].walkable = false;
    }
Beispiel #7
0
    public override void Start(NPC_Commune npc)
    {
        base.Start(npc);

        Duration = 0;

        // Path towards the station
        NPC.SetTargetCell(BuildableArea.GetCellFromPosition(Workstation.PickupZone));
    }
Beispiel #8
0
    public override void Start(NPC_Commune npc)
    {
        base.Start(npc);

        Duration = 0;

        // Path towards the soil
        NPC.SetTargetCell(BuildableArea.GetCellFromPosition(SoilBush.gameObject));
    }
Beispiel #9
0
    public override void Start(NPC_Commune npc)
    {
        base.Start(npc);

        // With timeout duration also
        Duration  = Random.Range(5, 10);
        TargetPos = BuildableArea.GetCellFromPosition(GameObject.FindObjectOfType <CityTravelZone>().transform.position);
        NPC.SetIfNotTargetCell(TargetPos);
    }
Beispiel #10
0
    void Start()
    {
        transform.GetChild(0).localScale *= BuildableArea.Instance.CellSize;

        // Ensure data grid is filled properly (in case added in editor)
        var cell = BuildableArea.GetCellFromPosition(gameObject);

        BuildableArea.Instance.Grid.nodes[cell.x, cell.y].Type = NesScripts.Controls.PathFind.NodeContent.TilledSoil;

        GrowBerryType = (Berry.BerryType)Random.Range(0, 9);

        TillSoilSound.pitch = Random.Range(0.85f, 1.05f);
        TillSoilSound.Play();
    }
    private void Start()
    {
        UpdateResources();

        // Ensure data grid is filled properly (in case added in editor)
        {
            // Workstation impassable
            NesScripts.Controls.PathFind.Point cell;
            foreach (var obj in new GameObject[] { gameObject, RightSide })
            {
                cell = BuildableArea.GetCellFromPosition(obj);
                BuildableArea.Instance.Grid.nodes[cell.x, cell.y].Type     = NesScripts.Controls.PathFind.NodeContent.Workstation;
                BuildableArea.Instance.Grid.nodes[cell.x, cell.y].walkable = false;
            }
        }
    }
Beispiel #12
0
    public override void Update()
    {
        base.Update();

        // Plant if reach
        if (NPC.CurrentPos == BuildableArea.GetCellFromPosition(SoilBush.gameObject))
        {
            SoilBush.Plant();
            SoilBush.AssignedNPC = null;

            NPC.TaskComplete();
        }

        // If plant is planted by someone else also move on
        if (SoilBush.CurrentStage != SoilBush.Stage.Tilled)
        {
            Finish();
        }
    }
Beispiel #13
0
    public override void Update()
    {
        base.Update();

        // Harvest if reach
        if (NPC.Berries == 0)
        {
            if (NPC.CurrentPos == BuildableArea.GetCellFromPosition(Bush.gameObject))
            {
                NPC.Berries       = Bush.Harvest();
                NPC.HeldBerryType = Bush.GrowBerryType;
                NPC.PickupItem(Bush.Berries[0].gameObject);
                Bush.AssignedNPC = null;
            }
        }
        else
        {
            if (DropOff == null)
            {
                FindWorkstation();
            }
            else
            {
                NPC.SetIfNotTargetCell(BuildableArea.GetCellFromPosition(DropOff.DropZone));
                if (NPC.CurrentPos == BuildableArea.GetCellFromPosition(DropOff.DropZone))
                {
                    // Remove number of berries accepted and repeat until hands empty
                    NPC.Berries = DropOff.AddBerry(NPC.Berries, NPC.HeldBerryType);
                    if (NPC.Berries != 0)
                    {
                        DropOff = null;
                    }
                    else
                    {
                        Finish();

                        NPC.DropItem();
                        NPC.TaskComplete();
                    }
                }
            }
        }
    }
Beispiel #14
0
    /// <summary>
    /// Sells the tower and reverts all necessary BA statuses
    /// </summary>
    public void SellTower()
    {
        if (GameplayManager.Instance.TowerToSell != null && !GameplayManager.Instance.IsPaused)
        {
            // Sets the Buildable area back to a normal Unoccupiead Area
            // bc2d needs to be reneabled due to it being disabled to avoid double triggering of
            // ba and tower
            GameplayManager.Instance.ScrapCollected += 50;
            BuildableArea ba = GameplayManager.Instance.TowerToSell.GetComponentInParent <BuildableArea>();
            ba.Occupied     = false;
            ba.bc2d.enabled = true;
            Instantiate(ParticleEffectManager.Instance.particleDictionary[ParticleEffectManager.ParticleToPlay.SCRAP_COLLECT], GameplayManager.Instance.TowerToSell.transform.position, Quaternion.identity);
            Instantiate(ParticleEffectManager.Instance.particleDictionary[ParticleEffectManager.ParticleToPlay.SCRAP_COLLECT], GameplayManager.Instance.TowerToSell.transform.position, Quaternion.identity);
            Instantiate(ParticleEffectManager.Instance.particleDictionary[ParticleEffectManager.ParticleToPlay.SCRAP_COLLECT], GameplayManager.Instance.TowerToSell.transform.position, Quaternion.identity);
            Instantiate(ParticleEffectManager.Instance.particleDictionary[ParticleEffectManager.ParticleToPlay.SCRAP_COLLECT], GameplayManager.Instance.TowerToSell.transform.position, Quaternion.identity);

            Destroy(GameplayManager.Instance.TowerToSell);
            CloseMenu();
        }
    }
Beispiel #15
0
    private void Awake()
    {
        Instance = this;

        Grid             = new NesScripts.Controls.PathFind.Grid(GridSquares, GridSquares);
        GridWithMovables = new NesScripts.Controls.PathFind.Grid(GridSquares, GridSquares);

        // Add default impasses (e.g. house etc)
        foreach (var area in DefaultImpasseAreas)
        {
            for (int x = (int)area.x; x < area.x + area.width; x++)
            {
                for (int y = (int)area.y; y < area.y + area.height; y++)
                {
                    Grid.nodes[x, y].Type     = NodeContent.Impasse;
                    Grid.nodes[x, y].walkable = false;
                    Grid.nodes[x, y].price    = 0;
                }
            }
        }
    }
Beispiel #16
0
    protected void UpdateMove()
    {
        IsWalking = false;
        if (Path.Count > 0)
        {
            // Lerp to each cell on the journey
            float   progress = (Time.time - CurrentMoveTime) / MoveTime;
            Vector3 start    = BuildableArea.GetPositionFromCell(CurrentPos.x, CurrentPos.y);
            Vector3 finish   = BuildableArea.GetPositionFromCell(Path[0].x, Path[0].y);
            transform.position = Vector3.Lerp(start, finish, progress);
            if (!GetComponent <Billboard>().enabled)
            {
                transform.LookAt(finish);
                transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y, 0);
            }

            UpdateFacing(start, finish);
            UpdateParentItemToCurrentHand();

            // Set new current once reached grid cell
            if (Time.time - CurrentMoveTime >= MoveTime)
            {
                CurrentPos = Path[0];
                Path.RemoveAt(0);
                CurrentMoveTime = Time.time;

                // TODO Testing regen path each tile, to avoid other NPCs/player
                SetTargetCell(TargetPos);
            }
        }
        else if (CurrentPos != TargetPos)
        {
            // Try to find new path if they still have a target unreached
            SetTargetCell(TargetPos);
        }
    }
Beispiel #17
0
 public void SetPos(Point cell)
 {
     CurrentPos         = cell;
     transform.position = BuildableArea.GetPositionFromCell(cell.x, cell.y);
 }