Esempio n. 1
0
    private void InterpretCommand(string command)
    {
        if (string.IsNullOrEmpty(command))
        {
            return;
        }

        var parts = command.Split(' ').ToList();
        var head  = GetCommandHead(parts);

        // spawn
        if (head.StartsWith("sp"))
        {
            InterpretSpawnCommand(parts);
            return;
        }

        // sleep
        if (head.StartsWith("sl"))
        {
            _timeToSleep = float.Parse(GetCommandHead(parts));
            return;
        }

        // order
        if (head.StartsWith("o"))
        {
            var secondPart = GetCommandHead(parts);
            if (secondPart.StartsWith("p"))
            {
                var pos = GetPos(parts);
                _townController.PushNewOrder(OrderType.PlantWheat, pos);
                return;
            }

            return;
        }

        // fastforward (ff)
        if (head.StartsWith("f"))
        {
            var secondPart = GetCommandHead(parts);
            var speed      = int.Parse(secondPart);
            GameApplication.Instance.ChangeTimeSpeed(speed);
            return;
        }

        // save
        if (head.StartsWith("sav"))
        {
            LoadSaveGame.SaveGameData();
            return;
        }

        // reload
        if (head.StartsWith("rel"))
        {
            LoadSaveGame.Instance.ReloadGame();
            return;
        }

        // reset
        if (head.StartsWith("res"))
        {
            LoadSaveGame.Instance.ResetGame();
            return;
        }

        // erase
        if (head.StartsWith("er"))
        {
            LoadSaveGame.Instance.EraseGame();
            return;
        }

        // add
        if (head.StartsWith("add"))
        {
            var          secondPart = GetCommandHead(parts);
            DropItemType type;
            // meat
            if (secondPart.StartsWith("m"))
            {
                type = DropItemType.Meat;
            }
            else if (secondPart.StartsWith("b"))
            {
                type = DropItemType.Bread;
            }
            else
            {
                Debug.LogError($"DropItemType {secondPart} not supported");
                return;
            }

            var ammountString = GetCommandHead(parts);
            var ammount       = uint.Parse(ammountString);
            _townController.AddToStorage(type, ammount);
            return;
        }

        Debug.LogError("Unrecognized command " + command);
    }
Esempio n. 2
0
    private void ProcessOrderState()
    {
        var orderCompleted = true;

        switch (_villagerModel.CurrentOrderType)
        {
        case OrderType.Eat:
            ProcessEatOrder();
            break;

        case OrderType.Sleep:
            _villagerModel.Sleepiness.Restore(_villagerModel.House.SleepinessRestore);
            if (!_villagerModel.Sleepiness.IsRestored())
            {
                orderCompleted = false;
            }

            break;

        case OrderType.Roam:
            break;

        case OrderType.Leave:
            --_townController.VillagersInIsland;
            Destroy(gameObject);
            break;

        case OrderType.PlantWheat:
            _spawnController.SpawnWheatCrop(_villagerModel.CurrentTownOrder.Position);
            break;

        case OrderType.PlantTofu:
            _spawnController.SpawnTofuCrop(_villagerModel.CurrentTownOrder.Position);
            break;

        case OrderType.Null:
            throw new ArgumentOutOfRangeException();

        case OrderType.PickItem:
            int ammount;
            var type = _townController.DestroyItem(_villagerModel.CurrentTownOrder.Position, out ammount);
            _villagerModel.Inventory[type] += ammount;
            _villagerController.AddOrder(OrderType.DropItem);
            break;

        case OrderType.DropItem:
            _townController.AddToStorage(_villagerModel.Inventory);
            _villagerModel.ResetInventory();
            break;

        case OrderType.HarvestPlant:
            _townController.HarvestCrop(_villagerModel.CurrentTownOrder.Position);
            break;

        case OrderType.BakeBreadFindWheat:
            GrabItemFromTownStorage(DropItemType.Wheat, OrderAmmount);
            _villagerController.AddOrder(OrderType.BakeBreadDropWheatInOven);
            break;

        case OrderType.GrowPigDropWheatInPen:
        case OrderType.BakeBreadDropWheatInOven:
            _townController.DropRawItemInFactory(_villagerModel.DestinationCell.Position,
                                                 _villagerModel.Inventory[DropItemType.Wheat]);
            _villagerModel.Inventory[DropItemType.Wheat] -= (int)OrderAmmount;
            break;

        case OrderType.FermentTofuFindSoybean:
            GrabItemFromTownStorage(DropItemType.Soybean, OrderAmmount);
            _villagerController.AddOrder(OrderType.FermentTofuDropSoybeanInFermenter);
            break;

        case OrderType.FermentTofuDropSoybeanInFermenter:
            _townController.DropRawItemInFactory(_villagerModel.DestinationCell.Position,
                                                 _villagerModel.Inventory[DropItemType.Soybean]);
            _villagerModel.Inventory[DropItemType.Soybean] -= (int)OrderAmmount;
            break;

        case OrderType.MakeMeatDropPiggyInSlaughterhouse:
            _townController.DropRawItemInFactory(_villagerModel.DestinationCell.Position,
                                                 _villagerModel.Inventory[DropItemType.Piggy]);
            _villagerModel.Inventory[DropItemType.Piggy] -= (int)OrderAmmount;
            break;

        case OrderType.FeedPigFindWheat:
            GrabItemFromTownStorage(DropItemType.Wheat, OrderAmmount);
            _villagerController.AddOrder(OrderType.GrowPigDropWheatInPen);
            break;

        case OrderType.MakeMeatFindPig:
            GrabItemFromTownStorage(DropItemType.Piggy, OrderAmmount);
            _villagerController.AddOrder(OrderType.MakeMeatDropPiggyInSlaughterhouse);
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        if (orderCompleted)
        {
            CurrentVillagerState = VillagerState.Idle;
        }
    }