コード例 #1
0
        public async Task <IActionResult> ResourceUsage([FromRoute] int id)
        {
            ResourceStats resourceStats = await statisticsService.GetResourceStats(id);

            ResourceStatsDTO dTO = dtoMapper.Map <ResourceStatsDTO>(resourceStats);

            return(Ok(dTO));
        }
コード例 #2
0
 public void Gather(ResourceStats resourceStats)
 {
     if (gatherCooldown <= 0f)
     {
         resourceStats.TakeDamage(myStats.gathering.GetValue());
         gatherCooldown = .75f / gatherSpeed;
     }
 }
コード例 #3
0
 // Update is called once per frame
 void Start()
 {
     resources = GameObject.Find("GM").GetComponent <ResourceStats>();
     InvokeRepeating("SpawnResources", generateAfterSeconds, generateAfterSeconds);
     health        = Random.Range(60f, 100f);
     resourcePool  = Random.Range(40f, 80f);
     steelPerRound = Random.Range(1, 6);
     woodPerRound  = Random.Range(1, 6);
 }
コード例 #4
0
 void Start()
 {
     Resources  = GameObject.Find("GameManager").GetComponent <ResourceStats>();
     foodText   = this.gameObject.transform.Find("foodBlock").Find("foodNum").GetComponent <Text>();
     lumberText = this.gameObject.transform.Find("lumberBlock").Find("lumberNum").GetComponent <Text>();
     cottonText = this.gameObject.transform.Find("cottonBlock").Find("cottonNum").GetComponent <Text>();
     furText    = this.gameObject.transform.Find("furBlock").Find("furNum").GetComponent <Text>();
     oreText    = this.gameObject.transform.Find("oreBlock").Find("oreNum").GetComponent <Text>();
 }
コード例 #5
0
        private List <ResourceStats> GetResourceStatsCollection(IEnumerable <Resource> resources)
        {
            List <ResourceStats> statsCollection = new List <ResourceStats>();

            foreach (var resource in resources)
            {
                ResourceStats stats = GetSpecificResourceStats(resource);
                statsCollection.Add(stats);
            }
            return(statsCollection);
        }
コード例 #6
0
        private void OnGUI()
        {
            if (globalHidden)
            {
                return;
            }
            if (FlightGlobals.fetch != null && FlightGlobals.ActiveVessel != null) // Check if in flight
            {
                if (FlightGlobals.ActiveVessel.isEVA)                              // EVA kerbal, do nothing
                {
                    return;
                }
                checkMode(DisplayMode.inFlight);
                checkWarp();
            }

            else   // Not in flight, in editor or F2 pressed unset the mode and return
            {
                checkMode(DisplayMode.none);
                return;
            }
            if (doOneFrame)
            {
                doOneFrame = !doOneFrame;

                //updateAmValues();
                timeIntervalMeasured = Planetarium.GetUniversalTime() - lastTimeCheck;
                lastTimeCheck        = Planetarium.GetUniversalTime();
                Log.Info("OnGUI 1");
                ResourceStats rs = VesselStatsManager.Instance.GetOrAdd(FlightGlobals.ActiveVessel);
                Log.Info("OnGUI 2");
                if (rs != null)
                {
                    Log.Info("OnGUI 3");
                    am_prod = -rs.GetGeneration("ElectricCharge") / timeIntervalMeasured;
                    am_use  = rs.GetConsumption("ElectricCharge") / timeIntervalMeasured;
                    Log.Info("OnGUI.GetTotalConsumption: " + (rs.GetConsumption("ElectricCharge") / timeIntervalMeasured).ToString());
                    Log.Info("OnGUI: " + (rs.GetGeneration("ElectricCharge") / timeIntervalMeasured).ToString());
                    rs.Reset();
                }
                Log.Info("OnGUI 4");

                checkWinBounds();


                //if (ToolbarManager.ToolbarAvailable)
                setTBIcon();
            }

            displayWindows();
        }
コード例 #7
0
    void HarvestingHive()
    {
        if (GameTime >= 1 && !test.isClosed)
        {
            test.agentName.Add(pathvalue.AgentName);
            test.deltaTime.Add(Time.time);
            test.pathValue.Add(PathValue);
            test.resourceValue.Add(ResourceValue);
            test.continuousMovement.Add(MoveingValue);
            test.currentState.Add(theState);
            test.hits.Add(HitValue);
            test.resourcePriority.Add(GetComponent <TaskInfo>().ResourcePriority);
            GameTime = 0;
        }
        if (Power >= 10)
        {
            ResourceValue = 1;
        }
        else if (Power < 10)
        {
            ResourceValue = (Power - 10f) / 10f;
        }
        agent.SetDestination(Hive.transform.position);

        if (Identify.currentHitObject)
        {
            if (Identify.currentHitObject.name == "Hive")
            {
                prevDelta = Vector3.Distance(HarvestInfo.transform.position, transform.position);

                Power = 0;
                HP   -= Random.Range(5, 20);
                if (HP <= 10)
                {
                    HP += 110;
                }
                LoadBar.fillAmount = Power;
                currState          = States.HarvestResource;
            }
        }
        if (HarvestInfo == null)
        {
            currState   = States.CheckHive;
            HarvestInfo = null;
            Task        = false;
        }
    }
コード例 #8
0
        /// <summary>
        /// Creates a CombatEntity using an EnemyEntityBase. The result is an ai-controlled CombatEntity.
        /// </summary>
        /// <param name="entityBase">The base to use for the resultant CombatEntity.</param>
        /// <returns></returns>
        public CombatEntity Create(AiEntityBase entityBase)
        {
            var secondaryStats = StatsCalculator.GetSecondaryStats(entityBase.Stats);

            secondaryStats += entityBase.SecondaryStats;

            int health    = entityBase.Resources.MaxHealth + StatsCalculator.GetHealth(entityBase.Stats);
            int mana      = entityBase.Resources.MaxMana + StatsCalculator.GetMana(entityBase.Stats);
            var resources = new ResourceStats
            {
                CurrentHealth       = health,
                CurrentMana         = mana,
                MaxHealth           = health,
                MaxMana             = mana,
                UnmodifiedMaxHealth = health,
                UnmodifiedMaxMana   = mana
            };

            var iconUris = new CharacterIconSet(entityBase.IconUris);
            var entity   = new CombatEntity
            {
                Id              = _id++,
                Name            = entityBase.Name,
                OwnerId         = GameplayConstants.AiId,
                IconUris        = iconUris,
                Abilities       = entityBase.Abilities,
                ComboCounter    = 0,
                OwnerName       = entityBase.FactionName,
                Stats           = entityBase.Stats.Copy(),
                SecondaryStats  = entityBase.SecondaryStats,
                StatusEffects   = new List <AppliedStatusEffect>(),
                UnmodifiedStats = entityBase.Stats,
                Resources       = resources
            };

            _statusEffectManager.Apply(entity, entity, entityBase.StatusEffects);

            return(entity);
        }
コード例 #9
0
        private ResourceStats GetSpecificResourceStats(Resource resource)
        {
            ResourceStats stats            = new ResourceStats();
            List <long>   timeSpansinTicks = new List <long>();
            double        cancellations    = 0;

            foreach (var booking in resource.Bookings)
            {
                if (booking.TerminationTime == null || booking.TerminationTime > booking.StartTime)
                {
                    timeSpansinTicks.Add((booking.EndTime - booking.StartTime).Ticks);
                }
                else
                {
                    cancellations++;
                }
            }

            long longAverageTicks = (long)timeSpansinTicks.Average();
            long minTicks         = timeSpansinTicks.Min();
            long maxTicks         = timeSpansinTicks.Max();
            long modeTicks        = timeSpansinTicks.GroupBy(n => n).OrderByDescending(g => g.Count()).Select(g => g.Key).FirstOrDefault();

            long maxRuleTime = new TimeSpan(0, resource.Rule.MaxTime.GetValueOrDefault(), 0).Ticks;

            stats.Id               = resource.Id;
            stats.Title            = resource.Title;
            stats.BookingsCount    = resource.Bookings.Count;
            stats.AverageTime      = new TimeSpan(longAverageTicks);
            stats.MinTime          = new TimeSpan(minTicks);
            stats.MaxTime          = new TimeSpan(maxTicks);
            stats.ModeTime         = new TimeSpan(modeTicks);
            stats.CancellationRate = cancellations / resource.Bookings.Count();
            stats.AverageUsageRate = (double)longAverageTicks / maxRuleTime;

            return(stats);
        }
コード例 #10
0
    void Harvesting()
    {
        if (GameTime >= 1 && !test.isClosed)
        {
            test.agentName.Add(pathvalue.AgentName);
            test.deltaTime.Add(Time.time);
            test.pathValue.Add(PathValue);
            test.resourceValue.Add(ResourceValue);
            test.continuousMovement.Add(MoveingValue);
            test.currentState.Add(theState);
            test.hits.Add(HitValue);
            test.resourcePriority.Add(GetComponent <TaskInfo>().ResourcePriority);
            GameTime = 0;
        }
        if (vel.magnitude == 0)
        {
            MoveingValue = -1;
        }
        else
        {
            MoveingValue = 1;
        }

        if (Power >= PowerLimit)
        {
            currState = States.HarvestHive;
        }
        else

        {
            if (HarvestInfo != null)
            {
                agent.SetDestination(HarvestInfo.transform.position);
            }
            if (Identify.currentHitObject)
            {
                if (Identify.currentHitObject.tag == "Tasks")
                {
                    Invoke("Scale", 1);
                    Timer += Time.deltaTime;
                    if (Timer > 20 && HarvestInfo.resourceEnergy < 10)
                    {
                        prevDelta  = Vector3.Distance(Hive.transform.position, transform.position);
                        PowerLimit = HarvestInfo.resourceEnergy;
                        Timer      = 0;
                        HarvestInfo.EnergyValue--;
                    }
                    else
                    {
                        prevDelta = Vector3.Distance(Hive.transform.position, transform.position);
                        Power++;
                        HarvestInfo.resourceEnergy--;
                        LoadBar.fillAmount = Power / PowerLimit;
                        HarvestInfo.EnergyValue--;
                    }
                    if (HarvestInfo.resourceEnergy >= 10)
                    {
                        PowerLimit = 10;
                    }
                }
            }
        }
        if (HarvestInfo == null)
        {
            currState   = States.CheckHive;
            HarvestInfo = null;
            Task        = false;
        }
    }
コード例 #11
0
 void Start()
 {
     Resources = GameObject.Find("GameManager").GetComponent <ResourceStats>();
     calcYield();
     testOutput();
 }
コード例 #12
0
 void Start()
 {
     resources = GameObject.Find("GM").GetComponent <ResourceStats>();
     health    = Random.Range(100f, 200f);
 }
コード例 #13
0
ファイル: TaskInfo.cs プロジェクト: KubilayColak/Swarm-Ai
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < listOfResources.Count; i++)
        {
            if (listOfResources[i])
            {
                if (listOfResources[i].GetComponent <ResourceStats>().EnergyValue >= currentresourceEnergy)
                {
                    highestResource       = listOfResources[i].GetComponent <ResourceStats>();
                    highestresourceEnergy = highestResource.EnergyValue;
                }
            }
        }

        if (currentResource == null && GetComponent <AgentMovement>().HarvestInfo != null)
        {
            currentResource = GetComponent <AgentMovement>().HarvestInfo;
        }
        else if (currentResource != null)
        {
            currentresourceEnergy = currentResource.EnergyValue;
        }

        ResourcePriority = Mathf.Clamp01(currentresourceEnergy / highestresourceEnergy);


        for (var i = listOfResources.Count - 1; i > -1; i--)
        {
            if (listOfResources[i] == null)
            {
                listOfResources.RemoveAt(i);
            }
        }

        if (Position.currentHitObject)
        {
            if (Position.currentHitObject.GetComponent <ResourceStats>())
            {
                ResourceStats resouce = Position.currentHitObject.GetComponent <ResourceStats>();

                if (resouce.addList)
                {
                    //print("already in list");
                }
                else if (!resouce.addList)
                {
                    resouce.addList = true;
                    listOfResources.Add(Position.currentHitObject);
                }
            }
            else if (Position.currentHitObject.GetComponent <HiveInfo>())
            {
                hiveinfo = Position.currentHitObject.GetComponent <HiveInfo>();
                if (!GetComponent <AgentMovement>().Task)
                {
                    if (hiveinfo.globalLocation.Count != 0)
                    {
                        AddItem(hiveinfo.globalLocation);
                        for (int i = 0; i < listOfResources.Count; i++)
                        {
                            if (listOfResources[i].GetComponent <ResourceStats>().EnergyValue > 0)
                            {
                                GetComponent <AgentMovement>().GetTask(listOfResources[i].GetComponent <ResourceStats>());
                                GetComponent <AgentMovement>().Task = true;
                                return;
                            }
                        }
                    }
                }
                else
                {
                    hiveinfo.AddItem(listOfResources);
                    AddItem(hiveinfo.globalLocation);
                }
            }
        }
        else
        {
        };
    }
コード例 #14
0
 void Start()
 {
     resourceStats = GetComponent <ResourceStats>();
     playerManager = PlayerManager.instance;
 }
コード例 #15
0
 public void GetTask(ResourceStats stat)
 {
     HarvestInfo = stat;
 }
コード例 #16
0
    void Update()
    {
        vel         = agent.velocity;
        agent.speed = speed;
        GameTime   += Time.deltaTime;

        if (vel.magnitude == 0)
        {
            stuckTime += Time.deltaTime;
            if (stuckTime >= 10)
            {
                currState = States.Scouting;
                stuckTime = 0;
            }
        }

        if (Identify.currentHitObject)
        {
            if (Identify.currentHitObject.tag == "Tasks")
            {
                Task        = true;
                HarvestInfo = Identify.currentHitObject.GetComponent <ResourceStats>();
            }
            if (Identify.currentHitObject.tag == "Enemy")
            {
                currState = States.Defend;
            }
        }
        if (Task)
        {
            if (Identify.currentHitObject)
            {
                if (Identify.currentHitObject.tag == "Tasks" || Identify.currentHitObject.tag == "Hive")
                {
                    TargetDestination = Identify.currentHitObject.transform;
                }
            }
            if (TargetDestination != null)
            {
                currDelta = Vector3.Distance(TargetDestination.position, agent.transform.position);
            }
            deltaThree = agent.speed;

            PathValue = deltaThree / (prevDelta - currDelta);

            if ((prevDelta - deltaThree) < currDelta)
            {
                PathValue = -1;
            }
        }
        else if (!Task)
        {
            HarvestInfo = null;
            Task        = false;
        }

        switch (currState)
        {
        case States.CheckHive:
        {
            theState = "CheckHive";
            thisRend.material.SetColor("_Color", Color.gray);
            Idle();
            break;
        }

        case States.Scouting:
        {
            anim.SetBool("isIdle", false);
            anim.SetBool("isSearch", true);
            theState = "Scouting";
            thisRend.material.SetColor("_Color", Color.yellow);
            MoveMent();
            break;
        }

        case States.HarvestResource:
        {
            anim.SetBool("isHarvest", true);
            anim.SetBool("isSearch", false);
            anim.SetBool("isDefend", false);
            theState = "HarvestResource";
            thisRend.material.SetColor("_Color", Color.green);
            Harvesting();
            break;
        }

        case States.HarvestHive:
        {
            anim.SetBool("isHarvest", true);
            anim.SetBool("isSearch", false);
            anim.SetBool("isDefend", false);
            theState = "HarvestHive";
            thisRend.material.SetColor("_Color", Color.green);
            HarvestingHive();
            break;
        }

        case States.Defend:
        {
            anim.SetBool("isDefend", true);
            anim.SetBool("isHarvest", false);
            anim.SetBool("isSearch", false);
            theState = "Defend";
            thisRend.material.SetColor("_Color", Color.red);
            Defending();
            break;
        }
        }
    }
コード例 #17
0
        /// <summary>
        /// Creates a player combat entity from a given character template asynchronously.
        /// </summary>
        /// <param name="template">The template containing specifications on how to create the entity.</param>
        /// <returns>Returns the combat entity if the operation was successful, else returns null.</returns>
        public async Task <CombatEntity> CreateAsync(CharacterTemplate template)
        {
            if (!await IsValidTemplateAsync(template))
            {
                return(null);
            }

            var hairData = await _characterHairRepo.GetDataAsync();

            var baseData = await _characterBaseRepo.GetDataAsync();

            var classTemplates = await _classTemplateRepo.GetDataAsync();

            ClassTemplate    cTemplate;
            CharacterIconSet iconUris;

            try
            {
                // Find the corresponding iconUris and arrange them in the correct order from
                // bottom layer to top
                var hair  = hairData.First(h => h.Id == template.HairId).IconUri;
                var cBase = baseData.First(b => b.Id == template.BaseId).IconUri;
                cTemplate = classTemplates.First(temp => temp.Id == template.ClassTemplateId);

                iconUris = new CharacterIconSet
                {
                    BaseIconUri = cBase,
                    HairIconUri = hair
                };
            }
            catch (InvalidOperationException e)
            {
                return(null);
            }

            int health    = StatsCalculator.GetHealth(cTemplate.Stats);
            int mana      = StatsCalculator.GetMana(cTemplate.Stats);
            var resources = new ResourceStats
            {
                CurrentHealth       = health,
                CurrentMana         = mana,
                MaxHealth           = health,
                MaxMana             = mana,
                UnmodifiedMaxHealth = health,
                UnmodifiedMaxMana   = mana
            };

            // Todo: Calculate secondary stats
            var character = new CombatEntity
            {
                Id              = _id++,
                Name            = template.Name,
                OwnerId         = template.OwnerId,
                IconUris        = iconUris,
                GroupId         = template.GroupId,
                OwnerName       = template.OwnerName,
                GrowthPoints    = template.AllocatedStats,
                Abilities       = cTemplate.Abilities.ToList(),
                Resources       = resources,
                SecondaryStats  = cTemplate.SecondaryStats.Copy(),
                StatusEffects   = new List <AppliedStatusEffect>(),
                UnmodifiedStats = cTemplate.Stats.Copy(),
                Stats           = cTemplate.Stats.Copy(),
                EquippedItems   = new List <Item>()
            };

            foreach (var equipment in cTemplate.EquippedItems)
            {
                _equipmentManager.Equip(character, equipment);
            }

            // Todo: Add to dbset here after creating EFCore migration

            return(character);
        }