Пример #1
0
    void TickFood()
    {
        int Food          = _resourceManager.GetResourceLevel(Assets.Scripts.ResourceTypes.ResourceTypes.FOOD);
        int foodDepletion = (int)(FoodPerPerson * _popScript.CurrentPopulation());

        if (foodDepletion < 1)
        {
            foodDepletion = 1;
        }
        _resourceManager.AddResource(Assets.Scripts.ResourceTypes.ResourceTypes.FOOD, -foodDepletion);
        Food = _resourceManager.GetResourceLevel(Assets.Scripts.ResourceTypes.ResourceTypes.FOOD);
        if (Food <= 0)
        {
            //KILL DEATH MURDER
            int popDepletion = (int)(Food / FoodPerPerson);


            _popScript.RemovePop();

            _resourceManager.AddResource(Assets.Scripts.ResourceTypes.ResourceTypes.FOOD, -Food);
            if (_popScript.CurrentPopulation() <= 0)
            {
                //Ya dead son
            }
        }
    }
Пример #2
0
 void UIAction(int what) {
         ComSat.Trace(this, "UIAction");
         if(what == clearQueue) {
                 foreach(var data in buildQueue) {
                         if(data.buildCollider != null) {
                                 buildMan.RemovePendingBuild(data.buildCollider);
                         }
                 }
                 buildQueue.Clear();
                 delay = 0;
                 resourceMan.AddResource(entity.team, ResourceType.Metal, usedResources.Metal);
                 resourceMan.AddResource(entity.team, ResourceType.MagicSmoke, usedResources.MagicSmoke);
                 ResetBuildTime();
         }
 }
Пример #3
0
    public void Select()
    {
        isSelected = !isSelected;
        if (isSelected == true)
        {
            if (resourceManager.actionPoints >= 10)
            {
                researchPanel.SelectResearch(this);
                GetComponent <Image> ().sprite = selectedResearchIcon;
                resourceManager.DeductResource(ResourceManager.ResourceType.ActionPoints, 10);
            }
            else
            {
                researchPanel.notificationPanel.text.text = "10 Action Points required";
                researchPanel.notificationPanel.gameObject.SetActive(true);
            }
        }
        if (isSelected == false)
        {
            //if (resourceManager.actionPoints <= 0)
            {
                researchPanel.DeselectResearch();
                GetComponent <Image> ().sprite = unSelectedResearchIcon;
                resourceManager.AddResource(ResourceManager.ResourceType.ActionPoints, 10);
            }
        }


        researchPanel.SetButtonInteractable();
        FindObjectOfType <AudioManager> ().Play("Research");
    }
Пример #4
0
 private void DropResources()
 {
     foreach (var drop in Drops)
     {
         drop.Position = t.position;
         ResourceManager.AddResource(drop.Type, drop.Amount, drop.Position);
     }
 }
Пример #5
0
    void Finish()
    {
        node.RemoveBlock();
        ResourceManager.AddResource(ResourceType.WOOD, 5);

        finished   = true;
        successful = true;
    }
Пример #6
0
 public void AdvanceTurn()
 {
     resManager.AddResource(ResourceManager.ResourceType.ActionPoints, 10 - resManager.actionPoints);
     currentTurn++;
     sustainableRegions = 0;
     GameObject.FindGameObjectWithTag("Main UI").GetComponent <MainUI>().UpdateUiText();
     GameObject.FindGameObjectWithTag("Main UI").GetComponent <MainUI>().ShowChecker();
 }
Пример #7
0
 public void AddResource(string viewId, string resource)
 {
     if (Contains(viewId))
     {
         throw new Exception("ViewManager: already contains such key");
     }
     ResourceManager.AddResource(viewId, resource);
 }
Пример #8
0
    void Update()
    {
        timeSinceLastDrop += Time.deltaTime;

        if (timeSinceLastDrop >= TickDuration)
        {
            timeSinceLastDrop = 0;
            ResourceManager.AddResource(Type, ResourceDrop, transform.position);
        }
    }
Пример #9
0
 void TickUpdate()
 {
     timer += ComSat.tickRate;
     if (entity.team != -1 && timer > 1 && powerSink.poweredOn)
     {
         var amount = Math.Min(powerSink.Powered() ? mineRate : mineRate / 2, source.amount);
         resourceMan.AddResource(entity.team, resource, amount);
         source.amount -= amount;
     }
     timer %= 1;
 }
Пример #10
0
    /// <summary>
    /// Item handler if the Item the player just interacted with is type of      Resource
    /// </summary>
    /// <param name="collision"></param>
    private void IfResourceItem(Collider2D collision)
    {
        if (collision.GetComponent <Item>().itemType == Item.ItemType.resource)
        {
            //Michael Schmidt
            //adding resource to resourceManager class
            resourceManager.AddResource(collision.GetComponent <Item>().itemName, collision.GetComponent <Item>().amount);

            collision.GetComponent <Item>().isPickedUp = true;
        }
    }
Пример #11
0
 private static void AddResourceWrapper(string res)
 {
     Console.Write(" * Adding {0}... ", res);
     if (ResourceManager.AddResource(res))
     {
         Console.Write("ok.\n");
     }
     else
     {
         Console.Write("fail!\n");
     }
 }
Пример #12
0
        private static void AddUpdateDeleteDynamicDataTest()
        {
            Console.WriteLine("Add_Update_Delete_DynamicData Test");
            //arrange
            ICacheProvider cacheProvider =
                new CacheProvider(new CacheItemPolicy
                {
                    AbsoluteExpiration = DateTimeOffset.MinValue,
                    SlidingExpiration = TimeSpan.Zero
                });
            IResourceManager resourceManager = new ResourceManager(cacheProvider);

            string expectedvalue = "5";
            string expectedNewValue = "6";

            var dynamicData = new DynamicTranslationsData
            {
                DescriptionValue = "5",
                DynamicKey = "5",
                Value = "5",
                LanguageId = 1
            };

            //Add dynamic data
            resourceManager.AddResource(dynamicData);
            Console.WriteLine("The dynamic data were added successfully");

            string actualValue = resourceManager.GetResource(TranslationTypeEnum.DynamicTranslation,
                dynamicData.DynamicKey, "uk");

            Console.WriteLine("ADDING... Actual value:{0} \t Expected value:{1}", actualValue, expectedvalue);
            Console.WriteLine("Press anykey to continue...");
            Console.ReadKey();

            //Update dynamic data
            dynamicData.Value = "6";
            resourceManager.UpdateResource(dynamicData);
            Console.WriteLine("The dynamic data were updateded successfully");

            string actualNewValue = resourceManager.GetResource(TranslationTypeEnum.DynamicTranslation,
                dynamicData.DynamicKey, "uk");

            Console.WriteLine("UPDATING... Actual value:{0} \t Expected value:{1}", actualNewValue, expectedNewValue);
            Console.WriteLine("Press anykey to continue...");
            Console.ReadKey();

            //Delete dynamic data
            resourceManager.DeleteDynamicResource(new List<string>(){"5"});
            Console.WriteLine("The dynamic data were deleted successfully");
            Console.WriteLine("Press anykey to finish current test.");
            Console.WriteLine("-----------------------------");
        }
Пример #13
0
    void DepositResources()
    {
        resourceManager.AddResource(currentlyGathering, resourcesCarried);
        if (currentlyGathering != ResourceTypes.None)
        {
            workersManager.gatheringWorkers[currentlyGathering]--;
            currentlyGathering = ResourceTypes.None;
        }
        resourcesCarried      = 0;
        exactResourcesCarried = 0;

        Task.current.Succeed();
    }
        public ActionResult Create(ResourceViewModel resourceViewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _resourceManager.AddResource(resourceViewModel);
                }
                catch (Exception ex)
                {
                    return(RedirectToAction("Index", "Error", new { message = ex.Message, stackTrace = ex.StackTrace }));
                }
                return(RedirectToAction("Index"));
            }

            return(View(resourceViewModel));
        }
Пример #15
0
 private void OnTriggerEnter(Collider other)
 {
     if (_built)
     {
         if (other.gameObject.tag == "Worker")
         {
             //Pass reasources
             Harvester h = other.gameObject.GetComponent <Harvester>();
             if (h != null)
             {
                 Debug.Log("Depsitiong resources");
                 _resourceManager.AddResource(h.typeHeld, h.amountHeld);
                 h.amountHeld = 0;
                 h.typeHeld   = ResourceTypes.NONE;
             }
         }
     }
 }
Пример #16
0
        void CreateResource(string name, float rariety, int spawnAmount, Mesh mesh, Texture2D texture, bool replaceGroundTexture)
        {
            int[]          finalTiles    = new int[rPossibleTiles.Count];
            List <Feature> finalFeatures = new List <Feature>();

            finalTiles = rPossibleTiles.ToArray();

            //fill feature list with data from rule.possibleFeatures
            for (int i = 0; i < rPossibleFeatures.Count; i++)
            {
                finalFeatures.Add(rPossibleFeatures[i]);
            }


            //nullify duplicate tiles
            for (int i = 0; i < rPossibleTiles.Count; i++)
            {
                for (int z = 0; z < rPossibleTiles.Count; z++)
                {
                    if (rPossibleTiles[i] == rPossibleTiles[z] && i != z)
                    {
                        rPossibleTiles.RemoveAt(z);
                    }
                }
            }
            finalTiles = rPossibleTiles.ToArray();

            //nullify duplicate features
            for (int i = 0; i < finalFeatures.Count; i++)
            {
                for (int z = 0; z < finalFeatures.Count; z++)
                {
                    if (finalFeatures[i] == finalFeatures[z] && i != z)
                    {
                        finalFeatures.RemoveAt(z);
                    }
                }
            }

            resourceManager.AddResource(new Resource(name, rariety, spawnAmount, mesh, texture, replaceGroundTexture, new HexRule(finalTiles, finalFeatures.ToArray())));
        }
Пример #17
0
    public void RefundEvent()
    {
        turnsToResolve.gameObject.SetActive(false);
        if (GetComponent <EventPopUpBase>().isResolving == true)
        {
            Debug.Log("Refund");
            resManager.AddResource(ResourceManager.ResourceType.ActionPoints, eventDataCopy.actionCost);
            cityOrign.AddCityResource(CityBase.ProductionType.Water, eventDataCopy.waterCost);
            cityOrign.AddCityResource(CityBase.ProductionType.Power, eventDataCopy.powerCost);
            cityOrign.AddCityResource(CityBase.ProductionType.Food, eventDataCopy.foodCost);
        }

        if (turnsLeft > 0)
        {
            GetComponent <Image>().sprite = timerSprites[turnsLeft - 1];
        }

        isResolving = false;
        this.GetComponent <Button>().interactable = true;
        Destroy(eventPanel);
    }
Пример #18
0
        static ServerInstance()
        {
            //Define image resource
            ResourceManager.AddResource(CometWorker.GetApplicationPath() + "pokein_logo.gif" //resource location
                                        , "Logo"                                             //public name of the resource
                                        , ResourceType.Image                                 //Image type
                                        , string.Empty                                       //This resource is application wide
                                        );

            string message = "PokeIn Library";

            byte[] bt = CometSettings.SerializationEncoding.GetBytes(message);
            //Define text resource
            ResourceManager.AddResource(ref bt
                                        , "Message"         //public name of the resource
                                        , ResourceType.Text //Text type
                                        , "txt"             //file type
                                        , string.Empty      //This resource is application wide
                                        );

            new Thread(delegate()
            {
                while (!CometWorker.IsApplicationRecycling)
                {
                    if (CometWorker.Groups.GroupHasMembers("ServerTime-Desktop"))
                    {
                        string ext = EXTML.Method("ServerTimeUpdated", DateTime.Now);
                        CometWorker.Groups.Send("ServerTime-Desktop", ext);
                    }

                    if (CometWorker.Groups.GroupHasMembers("ServerTime-Web"))
                    {
                        string json = JSON.Method("ServerTimeUpdated", DateTime.Now);
                        CometWorker.Groups.Send("ServerTime-Web", json);
                    }

                    Thread.Sleep(800);
                }
            }).Start();
        }
        // 创建通用Action容器
        public static void BuildCommonActionContainer()
        {
            // 创建通用Action容器
            var common = new CommonResource("Common");

            ResourceManager.AddResource(common);

            // 创建产品Action容器

            //_common.AddAction(new WaitAction("WaitAction"));
            //_common.AddAction(new ShowStatusAction("ShowStatusAction"));

            ////20180428Robin增加
            //_common.AddAction(new CallProcessAction("CallProcessAction"));

            ////////////////////////////////////////////
            // 加载外包里面的Action
            //BaseAction _action1 = CreateAction("WaitAction2", "WaitAction2");
            //_action1.ActionContainer = _common;
            //_common.AddAction(_action1);
            ////////////////////////////////////////////
        }
Пример #20
0
        /*void OnGetResourceLink(object inData)
         * {
         *      _decode = false;
         *      var table = (Hashtable) inData;
         *      StartCoroutine(WaitLoadLocalResource("http://" + table["url"].ToString().Replace("http://", "").Replace("https://", ""), (ResourceSource)table["type"], (Hashtable)table["post"]));
         * }*/

        /*void OnGetResourceLink(object inData)
         * {
         *      var table = (Hashtable) inData;
         *      //Debug.Log("OnGetResourceLink " + table["result"]);
         *      StartCoroutine(WaitLoadLocalResource("http://" + table["result"].ToString().Replace("http://", "").Replace("https://", ""),
         *                                                                              _type, table,null));
         * }*/

        void OnGetResources(object inData)
        {
            if (Gateway.Debug)
            {
                ULog.Log("ResourceLoader.OnGetResource(key:" + _key + ") " + inData);
            }
            var table = (Hashtable)inData;

            if (Gateway.Debug)
            {
                foreach (DictionaryEntry entry in table)
                {
                    ULog.Log("OnGetResource Hashtable: " + entry.Key + " : " + entry.Value);
                }
            }

            if (table.ContainsKey("url"))
            {
                _decode = (bool)table["decode"];
                StartCoroutine(
                    WaitLoadResources(
                        Gateway.Host + Gateway.Path + Gateway.File.Replace(".php", ".ogg"),
                        _resourceType,
                        new Hashtable {
                    { "r", _resourceType }, { "n", table["url"].ToString() }
                }));
            }
            else
            {
                var res = ResourceManager.AddResource(_key, table["result"]);
                if (_callback != null)
                {
                    _callback(_key, res);
                }
                Destroy(gameObject);
            }
        }
Пример #21
0
    public IEnumerator ExecuteAction(Action action)
    {
        Executing = true;
        if (action.Type == ActionType.Cut)
        {
            Tile tile = action.TargetObject.GetComponent <Tile>();
            if (tile != null)
            {
                character.WalkToCoordinates(tile.X, tile.Y);
                yield return(new WaitUntil(() => (character.cX == tile.X && character.cY == tile.Y)));

                yield return(new WaitForSeconds(1.0f));

                GameObject droppedResource = tile.item.GetComponent <DestructableItem>().droppedResource;
                Destroy(tile.item);
                tile.item = null;
                tile.ClearTag();
                GameObject resource = Instantiate(droppedResource, action.TargetObject.GetComponent <Renderer>().bounds.center, Quaternion.identity);
                resource.name = droppedResource.name + " (" + tile.X + "," + tile.Y + ")";
                tile.AddItem(resource);
                if (tile.zone == Zone.Stockpile)
                {
                    resources.AddResource(resource.GetComponent <Item>().resource, 1);
                }
                action.SetStatus(Status.Successful);
            }
            else
            {
                action.SetStatus(Status.Failed);
            }
            tile.Free(gameObject);
        }
        else if (action.Type == ActionType.Haul)
        {
            Item item = action.TargetObject.GetComponent <Item>();
            if (item != null)
            {
                List <GameObject> emptyTiles = manager.GetEmptyStockpileTiles();
                if (emptyTiles.Count > 0)
                {
                    bool a      = false;
                    Tile target = null;
                    for (int i = 0; i < emptyTiles.Count; i++)
                    {
                        target = emptyTiles[i].GetComponent <Tile>();
                        a      = target.GetLock(gameObject);
                        if (a)
                        {
                            break;
                        }
                    }
                    if (a)
                    {
                        target.GetLock(gameObject);
                        Tile parent = item.Parent.GetComponent <Tile>();
                        character.WalkToCoordinates(parent.X, parent.Y);
                        yield return(new WaitUntil(() => (character.cX == parent.X && character.cY == parent.Y)));

                        if (character.PickUpItem(parent))
                        {
                            character.WalkToCoordinates(target.X, target.Y);
                            yield return(new WaitUntil(() => (character.cX == target.X && character.cY == target.Y)));

                            character.DropItem(target);
                            resources.AddResource(item.resource, 1);
                            action.SetStatus(Status.Successful);
                            target.Free(gameObject);
                        }
                        else
                        {
                            action.SetStatus(Status.Failed);
                        }
                    }
                    else
                    {
                        action.SetStatus(Status.Failed);
                        Debug.Log(transform.name + " couldn't find a free stockpile tile to haul item: " + item.name);
                    }
                }
            }
            else
            {
                action.SetStatus(Status.Failed);
            }
        }
        else if (action.Type == ActionType.Build)
        {
            Tile       tile         = action.TargetObject.GetComponent <Tile>();
            GameObject passableTile = manager.GetPassableNeighbourTile(tile);
            int        resourceCost = tile.toBuild.GetComponent <BuildableItem>().resourceCost;
            int        count        = 0;
            if (passableTile != null)
            {
                for (int i = 0; i < resourceCost; i++)
                {
                    List <GameObject> resources = manager.GetItemsOfResourceInStockpile(tile.toBuild.GetComponent <BuildableItem>().requiredResource);
                    Item resource = resources[0].GetComponent <Item>();
                    if (resource.GetLock(gameObject))
                    {
                        Tile resourceTile = resource.Parent.GetComponent <Tile>();
                        character.WalkToCoordinates(resourceTile.X, resourceTile.Y);
                        yield return(new WaitUntil(() => (character.AtPosition(resourceTile.X, resourceTile.Y))));

                        character.PickUpItem(resourceTile);
                        Tile destTile = passableTile.GetComponent <Tile>();
                        character.WalkToCoordinates(destTile.X, destTile.Y);
                        yield return(new WaitUntil(() => (character.cX == destTile.X && character.cY == destTile.Y)));

                        character.DestroyItem();
                        count++;
                    }
                    else
                    {
                        break;
                    }
                }
                if (count == resourceCost)
                {
                    buildManager.Build(action.TargetObject, tile.toBuild);
                    action.SetStatus(Status.Successful);
                    tile.Free(gameObject);
                    tile.ClearTag();
                }
                else
                {
                    action.SetStatus(Status.Failed);
                }
            }
            else
            {
                action.SetStatus(Status.Failed);
            }
            tile.Free(gameObject);
        }
        else if (action.Type == ActionType.PickUpItem)
        {
            List <GameObject> items = manager.GetItemsOfResource(action.TargetObject.GetComponent <Item>().resource);
            if (items.Count > 0)
            {
                GameObject g      = items[manager.GetRandomInt(0, items.Count)];
                Item       item   = g.GetComponent <Item>();
                Tile       parent = item.Parent.GetComponent <Tile>();
                if (item.GetLock(gameObject) && character.WalkToCoordinates(parent.X, parent.Y))
                {
                    yield return(new WaitUntil(() => (character.AtPosition(parent.X, parent.Y))));

                    if (character.PickUpItem(parent))
                    {
                        action.SetStatus(Status.Successful);
                    }
                    else
                    {
                        action.SetStatus(Status.Failed);
                    }
                }
                else
                {
                    action.SetStatus(Status.Resend);
                }
            }
            else
            {
                action.SetStatus(Status.Failed);
            }
        }
        else if (action.Type == ActionType.TalkToTarget)
        {
            GameObject targetCharacter = GameObject.Find(action.TargetObject.name);
            if (targetCharacter == gameObject)
            {
                dialogueManager.Speak(gameObject, action.Dialog);
                yield return(new WaitForSeconds(5.0f));

                action.SetStatus(Status.Successful);
            }
            else
            {
                Character c = targetCharacter.GetComponent <Character>();
                if (c.GetLock(gameObject))
                {
                    yield return(new WaitUntil(() => c.currentAction == null));

                    Tile tile = manager.GetPassableNeighbourTile(manager.Map[c.cX, c.cY].GetComponent <Tile>()).GetComponent <Tile>();
                    character.WalkToCoordinates(tile.X, tile.Y);
                    yield return(new WaitUntil(() => (character.AtPosition(tile.X, tile.Y))));

                    dialogueManager.Speak(gameObject, action.Dialog);
                    yield return(new WaitForSeconds(5.0f));

                    action.SetStatus(Status.Successful);
                }
                else
                {
                    action.SetStatus(Status.Resend);
                }
            }
        }
        else if (action.Type == ActionType.GiveItemToTarget)
        {
            if (character.heldItem.GetComponent <Item>().resource == action.Precondition.HoldingItem.GetComponent <Item>().resource)
            {
                GameObject targetCharacter = GameObject.Find(action.TargetObject.name);
                Character  c = targetCharacter.GetComponent <Character>();
                if (c.GetLock(gameObject))
                {
                    Tile tile = manager.GetPassableNeighbourTile(manager.Map[c.cX, c.cY].GetComponent <Tile>()).GetComponent <Tile>();
                    character.WalkToCoordinates(tile.X, tile.Y);
                    yield return(new WaitUntil(() => (character.AtPosition(tile.X, tile.Y))));

                    character.DestroyItem();
                    if (action.Dialog != "")
                    {
                        dialogueManager.Speak(gameObject, action.Dialog);
                        yield return(new WaitForSeconds(5.0f));
                    }
                    action.SetStatus(Status.Successful);
                }
                else
                {
                    action.SetStatus(Status.Resend);
                }
            }
            else
            {
                action.SetStatus(Status.Failed);
            }
        }
        else if (action.Type == ActionType.Eat)
        {
            if (character.heldItem.GetComponent <Item>().resource == action.Precondition.HoldingItem.GetComponent <Item>().resource)
            {
                Character c = GetComponent <Character>();
                if (c.GetLock(gameObject))
                {
                    character.DestroyItem();
                    if (action.Dialog != "")
                    {
                        dialogueManager.Speak(gameObject, action.Dialog);
                        yield return(new WaitForSeconds(5.0f));
                    }
                    action.SetStatus(Status.Successful);
                }
                else
                {
                    action.SetStatus(Status.Resend);
                }
            }
            else
            {
                action.SetStatus(Status.Failed);
            }
        }
        else
        {
            Debug.Log("Action not found!");
            action.SetStatus(Status.Failed);
        }
        StartCoroutine(SendToTarget(action));
        Executing = false;
    }
Пример #22
0
 public void AddResource(UploadResourceContract resourceInfoSkeleton)
 {
     m_resourceManager.AddResource(resourceInfoSkeleton);
 }
Пример #23
0
        private void AddGoldResourceToPlayer()
        {
            Resource resource = resManager.GetResourceByResourceType(resourceTypeGold);

            resManager.AddResource(resource, resourceAmountGold);
        }
Пример #24
0
 void Harvest()
 {
     ResourceManager.AddResource(ResourceType.Time, ResourceDropPerHit, drill.position);
 }
Пример #25
0
    private void OnDestroy()
    {
        rm.AddResource(material, value);

        //TODO: block destruction animation
    }
    void ProcessFileTransmissionInfo(byte[] data)
    {
        string datastr = encoding.GetString(data);

        byte[] filedatabuffer;

        if (datastr.StartsWith("Req:"))
        {
            ResourceData resource = ResourceManager.GetResource(datastr.Substring(4, datastr.IndexOf("$") - 4));
            if (!FTContainer.UploadQueue.Contains(resource.path))
            {
                UploadFile(resource);
            }
            return;
        }

        if (datastr.StartsWith("FT:"))
        {
            int    infodelim = datastr.IndexOf("$"), iddelim = datastr.IndexOf('|');
            string filename = datastr.Substring(3, iddelim - 3), Id = datastr.Substring(iddelim + 1, infodelim - iddelim - 1);
            if (ResourceManager.GetResource(Id) != null)
            {
                FTContainer.Transdata = ResourceManager.GetResource(Id);
                FTContainer.Transdata.ChangeResourcePath(Path.GetDirectoryName(FTContainer.Transdata.path) + filename, FTContainer.Transdata.URI.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative);
                FTContainer.IsReceivingUpdate = true;
            }
            else
            {
                FTContainer.Transdata = new ResourceData(ResourceManager.GetDLResourceFolderPath() + filename, Id, UriKind.Relative);
            }
            string cstr = datastr.Substring(0, infodelim + 1);

            FTContainer.filestream = new FileStream(FTContainer.Transdata.path, FileMode.Create);

            int clength = data.Length - encoding.GetByteCount(cstr);
            if (clength > 0)
            {
                filedatabuffer = new byte[clength];
                Buffer.BlockCopy(data, encoding.GetByteCount(cstr), filedatabuffer, 0, filedatabuffer.Length);
                FTContainer.filestream.Write(filedatabuffer, 0, filedatabuffer.Length);
            }
            else
            {
                filedatabuffer = new byte[0];
            }

            DebugLogging("File Receiving..." + FTContainer.Transdata.name + FTContainer.Transdata.extension + " Id : " + FTContainer.Transdata.Id);
            DebugLogging("Received File Data :" + FTContainer.filestream.Length + " ( +" + FTContainer.filestream.Length);

            if (datastr.EndsWith("$End"))
            {
                FTContainer.filestream?.Close();
                if (FTContainer.IsReceivingUpdate)
                {
                    FTContainer.Transdata.IssueFinishedUpdateNotify();
                }
                else
                {
                    ResourceManager.AddResource(FTContainer.Transdata);
                }
                OnDownloadCompleted?.Invoke(FTContainer);

                DebugLogging("File Received successfully " + FTContainer.Transdata.name + FTContainer.Transdata.extension + " Id : " + FTContainer.Transdata.Id);

                FTContainer.IsReceivingUpdate = false;
                FTContainer.Transdata         = null;
            }
        }
        else if (datastr.EndsWith("$End"))
        {
            int slength = data.Length - encoding.GetByteCount("$End");
            if (slength > 0)
            {
                byte[] fdata = new byte[data.Length - encoding.GetByteCount("$End")];
                Buffer.BlockCopy(data, 0, fdata, 0, fdata.Length);
                //FTContainer.filebuffer = FTContainer.filebuffer.Concat(fdata).ToArray();
                FTContainer.filestream.Write(fdata, 0, fdata.Length);

                DebugLogging("Received File Data :" + FTContainer.filestream.Length + " ( +" + fdata.Length);
            }
            try
            {
                FTContainer.filestream?.Close();
                if (FTContainer.IsReceivingUpdate)
                {
                    FTContainer.Transdata.IssueFinishedUpdateNotify();
                }
                else
                {
                    ResourceManager.AddResource(FTContainer.Transdata);
                }
                OnDownloadCompleted?.Invoke(FTContainer);

                DebugLogging("File Received successfully " + FTContainer.Transdata.name + FTContainer.Transdata.extension + " Id : " + FTContainer.Transdata.Id);

                FTContainer.IsReceivingUpdate = false;
                FTContainer.Transdata         = null;
            }
            catch (Exception ex)
            {
                DebugLogging(ex.Message + "\n" + ex.StackTrace);
            }
        }
        else
        {
            if (!FTContainer.filestream.CanWrite)
            {
                return;
            }

            FTContainer.filestream.Write(data, 0, data.Length);
            //FTContainer.filebuffer = FTContainer.filebuffer.Concat(data).ToArray();

            DebugLogging("Received File Data :" + FTContainer.filestream.Length + " ( +" + data.Length);
        }
    }
Пример #27
0
    private void Update()
    {
        float distanceX = transform.position.x - Target.position.x;

        if (!IsAttacking)
        {
            if (distanceX > 0)
            {
                transform.localScale = new Vector3(-0.3f, 0.3f, 0.3f);
            }
            else
            {
                transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            }
        }

        if (enemyType == EnemyType.Slime)
        {
            slimeSoundTimer += 1f * Time.deltaTime;

            if (slimeSoundTimer >= 1f)
            {
                audio.Play();
                slimeSoundTimer = 0f;
            }
        }

        if (EnemyHealth <= 0)
        {
            this.gameObject.SetActive(false);
            int coins = Random.Range(0, 4);
            resourceManager.AddResource(ResourceType.Gold, coins);
            resourceManager.AddResource(ResourceType.Kills, 1);
        }

        AttackDelay -= Time.deltaTime;

        if (Vector2.Distance(transform.position, Target.position) > StoppingDistance && IsAttacking == false && playerHealth.PlayerHasDied == false)
        {
            transform.position = Vector2.MoveTowards(transform.position, Target.position, MoveSpeed * Time.deltaTime);
        }
        else if (Vector2.Distance(transform.position, Target.position) < StoppingDistance && WasInRange == false && playerHealth.PlayerHasDied == false)
        {
            transform.position      = this.transform.position;
            AttackAnimationDuration = StartAttackAnimationDuration;
            WasInRange = true;
        }

        if (WasInRange && AttackAnimationDuration >= 0)
        {
            if (IsAttacking)
            {
                AttackAnimationDuration -= Time.deltaTime;
            }

            if (Ranged && AttackDelay < 0)
            {
                IsAttacking = true;
                anim.SetBool("IsAttacking", true);
            }
            else if (!Ranged && AttackDelay < 0)
            {
                IsAttacking = true;
                anim.SetBool("IsAttacking", true);
                AttackDelay = StartAttackDelay;

                if (AttackAnimationDuration < AttackHitboxAppear)
                {
                    AttackTrigger.SetActive(true);
                }
            }

            if (AttackAnimationDuration < 0 || playerHealth.PlayerHasDied)
            {
                anim.SetBool("IsAttacking", false);
                WasInRange  = false;
                IsAttacking = false;

                if (!Ranged)
                {
                    AttackTrigger.SetActive(false);
                }
            }
        }
    }
Пример #28
0
    //Build and upgrade buildings when the requirements are met in order to activate the respective gameobject.
    void BeginnBuild()
    {
        if (doBuild == true && isBuild != true && Input.GetKeyDown(KeyCode.F) && resourceManager.wood >= 10)
        {
            resourceManager.AddResource("Wood", -10);

            Wood.gameObject.SetActive(true);
            isBuild = true;

            buildPhase = "Wood";

            if (buildFX != null)
            {
                Instantiate(buildFX, this.transform.position, Quaternion.identity);
            }

            timeBehaviour.timeCost = timeBehaviour.crafting;
        }

        else if (doBuild == true && isBuild == true && Stone.gameObject.activeSelf == false && Iron.gameObject.activeSelf == false && Input.GetKeyDown(KeyCode.F) && resourceManager.wood >= 20 && resourceManager.stone >= 10 && health == maxHealth)
        {
            resourceManager.AddResource("Wood", -20);
            resourceManager.AddResource("Stone_Chunk", -10);

            Wood.gameObject.SetActive(false);
            Stone.gameObject.SetActive(true);

            health    = 400;
            maxHealth = 400;

            buildPhase = "Stone";

            if (buildFX != null)
            {
                Instantiate(buildFX, this.transform);
            }

            timeBehaviour.timeCost = timeBehaviour.crafting;
        }

        else if (doBuild == true && isBuild == true && Stone.gameObject.activeSelf == true && Iron.gameObject.activeSelf == false && Input.GetKeyDown(KeyCode.F) && resourceManager.wood >= 10 && resourceManager.stone >= 10 && resourceManager.iron >= 10 && health == maxHealth)
        {
            resourceManager.AddResource("Wood", -10);
            resourceManager.AddResource("Stone_Chunk", -10);
            resourceManager.AddResource("Iron_Chunk", -10);

            Stone.gameObject.SetActive(false);
            Iron.gameObject.SetActive(true);

            health    = 600;
            maxHealth = 600;

            buildPhase = "Iron";

            if (buildFX != null)
            {
                Instantiate(buildFX, this.transform);
            }

            timeBehaviour.timeCost = timeBehaviour.crafting;
        }
    }
Пример #29
0
 public void AddExcept(int index)
 {
     resourceManager.AddResource(GetResourcesExcept(index));
 }