Пример #1
0
 public static void SetSelectedObject(this LocalInputHandler instance, SimulationObjectView view)
 {
     if (view == default(SimulationObjectView))
         instance.SetSelectedObjectId(-1);
     else
         instance.SetSelectedObjectId(view.Id);
 }
Пример #2
0
 private void Blacklist(SimulationObjectView target, TimeSpan duration)
 {
     _blacklist[target] = new Blacklisted()
     {
         Target    = target,
         Timestamp = DateTime.Now + duration,
     };
 }
Пример #3
0
        public bool IdentifiedTarget(out SimulationObjectView target)
        {
            var resources = _client.GetEntities <HarvestableObjectView>(ValidateHarvestable);
            var hostiles  = _client.GetEntities <MobView>(ValidateMob);

            var views = new List <SimulationObjectView>();

            foreach (var r in resources)
            {
                views.Add(r);
            }
            //foreach (var h in hostiles) views.Add(h);

            target = views.OrderBy((view) =>
            {
                var playerPosition   = _localPlayerCharacterView.transform.position;
                var resourcePosition = view.transform.position;

                var score = (resourcePosition - playerPosition).sqrMagnitude;

                if (view is HarvestableObjectView harvestable)
                {
                    var rareState = harvestable.GetRareState();

                    if (harvestable.GetTier() >= 3)
                    {
                        score /= 2;
                    }
                    if (harvestable.GetCurrentCharges() == harvestable.GetMaxCharges())
                    {
                        score /= 2;
                    }
                    if (rareState > 0)
                    {
                        score /= rareState;
                    }
                }
                else if (view is MobView mob)
                {
                }

                var yDelta = Math.Abs(_landscape.GetLandscapeHeight(playerPosition.c()) - _landscape.GetLandscapeHeight(resourcePosition.c()));

                score += (yDelta * 10f);

                return((int)score);
            }).FirstOrDefault();

            if (target != null)
            {
                Core.Log($"Resource spotted: {target.name}");
            }

            return(target != default(SimulationObjectView));
        }
Пример #4
0
 public static void SetSelectedObject(this LocalPlayerCharacterView instance, SimulationObjectView simulation)
 {
     if (simulation == default(SimulationObjectView))
     {
         instance.InputHandler.SetSelectedObjectId(-1L);
     }
     else
     {
         instance.InputHandler.SetSelectedObjectId(simulation.Id);
     }
 }
Пример #5
0
        public static float GetColliderExtents(this SimulationObjectView instance)
        {
            if (instance is HarvestableObjectView)
            {
                return(2.0f);
            }

            var collider = instance.GetComponent <Collider>();

            return(collider.GetColliderExtents());
        }
Пример #6
0
        public static bool ColliderContains(this SimulationObjectView instance, Vector3 location)
        {
            var collider = instance.GetComponent <Collider>();
            var bounds   = collider.bounds;

            if (bounds.Contains(location))
            {
                return(true);
            }

            return(false);
        }
Пример #7
0
        public bool ValidateTarget(SimulationObjectView target)
        {
            if (target is HarvestableObjectView resource)
            {
                return(ValidateHarvestable(resource));
            }

            if (target is MobView mob)
            {
                return(ValidateMob(mob));
            }

            return(false);
        }
        public ClusterPathingRequest(LocalPlayerCharacterView player, SimulationObjectView target, List <Vector3> path, bool useCollider = true)
        {
            _player = player;
            _target = target;

            _path = path;

            _useCollider = useCollider;

            _state = new StateMachine <State, Trigger>(State.Start);

            _state.Configure(State.Start)
            .Permit(Trigger.ApprachTarget, State.Running);

            _state.Configure(State.Running)
            .Permit(Trigger.ReachedTarget, State.Finish);
        }
Пример #9
0
        public void Search()
        {
            if (_localPlayerCharacterView.IsUnderAttack(out FightingObjectView attacker))
            {
                Core.Log("[Attacked]");
                _state.Fire(Trigger.EncounteredAttacker);
                return;
            }

            if (_localPlayerCharacterView.GetLoadPercent() > CapacityForBanking)
            {
                Core.Log("Overweight");
                _state.Fire(Trigger.Overweight);
                return;
            }

            if (_currentTarget != null)
            {
                Core.Log("[Blacklisting target]");

                Blacklist(_currentTarget, TimeSpan.FromMinutes(0.5f));

                _currentTarget         = null;
                _harvestPathingRequest = null;

                return;
            }

            if (IdentifiedTarget(out SimulationObjectView target))
            {
                Core.Log("[Checking Target]");
                _currentTarget = target;
            }

            if (_currentTarget != null && ValidateTarget(_currentTarget))
            {
                Core.Log("[Identified]");
                _state.Fire(Trigger.DiscoveredResource);
                return;
            }
        }
Пример #10
0
        public static float GetColliderExtents(this SimulationObjectView instance)
        {
            if (instance is HarvestableObjectView resource)
            {
                return(2.0f);
            }

            var collider = instance.GetComponent <Collider>();

            if (collider is SphereCollider sphere)
            {
                return(sphere.radius);
            }
            else if (collider is CapsuleCollider capsule)
            {
                return(capsule.radius);
            }
            else if (collider is BoxCollider box)
            {
                return(box.size.sqrMagnitude);
            }

            return(1.0f);
        }
 public static void SetSelectedObject(this LocalPlayerCharacterView instance, SimulationObjectView target) => instance.InputHandler.SetSelectedObject(target);
Пример #12
0
        public bool IdentifiedTarget(out SimulationObjectView target)
        {
            var views = new List <SimulationObjectView>();

            if (_allowMobHunting)
            {
                var hostiles = _client.GetEntities <MobView>(ValidateMob);
                foreach (var h in hostiles)
                {
                    if (h.GetResourceType().HasValue)
                    {
                        views.Add(h);
                    }
                }
            }

            var resources = _client.GetEntities <HarvestableObjectView>(ValidateHarvestable);

            foreach (var r in resources)
            {
                views.Add(r);
            }

            var filteredViews = views.Where(view =>
            {
                if (_skipUnrestrictedPvPZones && _landscape.IsInAnyUnrestrictedPvpZone(view.transform.position))
                {
                    return(false);
                }

                if (_skipKeeperPacks && ContainKeepers(view.transform.position))
                {
                    return(false);
                }

                if (view is HarvestableObjectView harvestable)
                {
                    var harvestableObject = harvestable.GetHarvestableObject();

                    var resourceType     = harvestableObject.GetResourceType().Value;
                    var tier             = (Tier)harvestableObject.GetTier();
                    var enchantmentLevel = (EnchantmentLevel)harvestableObject.GetRareState();

                    var info = new GatherInformation(resourceType, tier, enchantmentLevel);

                    return(_gatherInformations[info]);
                }
                else if (view is MobView mob)
                {
                    var resourceType     = mob.GetResourceType().Value;
                    var tier             = (Tier)mob.GetTier();
                    var enchantmentLevel = (EnchantmentLevel)mob.GetRareState();

                    var info = new GatherInformation(resourceType, tier, enchantmentLevel);

                    return(_gatherInformations[info]);
                }
                else
                {
                    return(false);
                }
            });

            target = filteredViews.OrderBy((view) =>
            {
                var playerPosition   = _localPlayerCharacterView.transform.position;
                var resourcePosition = view.transform.position;

                var score = (resourcePosition - playerPosition).sqrMagnitude;

                if (view is HarvestableObjectView harvestable)
                {
                    var harvestableObject = harvestable.GetHarvestableObject();
                    var rareState         = harvestableObject.GetRareState();

                    if (harvestableObject.GetTier() >= 3)
                    {
                        score /= (harvestableObject.GetTier() - 1);
                    }
                    if (harvestableObject.GetCharges() == harvestableObject.GetMaxCharges())
                    {
                        score /= 2;
                    }
                    if (rareState > 0)
                    {
                        score /= ((rareState + 1) * (rareState + 1));
                    }
                }
                else if (view is MobView mob)
                {
                    var rareState = mob.GetRareState();

                    if (mob.GetTier() >= 3)
                    {
                        score /= (mob.GetTier() - 1);
                    }
                    //if (mob.GetCurrentCharges() == mob.GetMaxCharges()) score /= 2;
                    if (rareState > 0)
                    {
                        score /= ((rareState + 1) * (rareState + 1));
                    }
                }

                var yDelta = Math.Abs(_landscape.GetTerrainHeight(playerPosition.c(), out RaycastHit A_1) - _landscape.GetTerrainHeight(resourcePosition.c(), out RaycastHit A_2));

                score += (yDelta * 10f);

                return((int)score);
            }).FirstOrDefault();

            if (target != null)
            {
                Core.Log($"Resource spotted: {target.name}");
            }

            return(target != default(SimulationObjectView));
        }
        public static bool TryFindPath(this LocalPlayerCharacterView instance, AStarPathfinder pathfinder, SimulationObjectView target,
                                       StopFunction <Vector2> stopFunction, out List <Vector3> results)
        {
            results = new List <Vector3>();

            if (instance.TryFindPath(pathfinder, target.transform.position, stopFunction, out results))
            {
                /*
                 * var collider = target.GetComponent<Collider>();
                 *
                 * if (collider != null)
                 * {
                 *      while (collider.bounds.Contains(results.Last()))
                 *              results.RemoveAt(results.Count - 1);
                 *
                 *      var lastNode = results.Last();
                 *      var closestNode = collider.ClosestPointOnBounds(lastNode);
                 *      var direction = (closestNode - lastNode).normalized / 2;
                 *
                 *      results.Add(closestNode - direction);
                 * }
                 *
                 * results.Insert(0, instance.transform.position);
                 */
            }
            else
            {
                return(false);
            }

            return(true);
        }
Пример #14
0
        public bool IdentifiedTarget(out SimulationObjectView target)
        {
            var resources = _client.GetEntities <HarvestableObjectView>(ValidateHarvestable);
            var hostiles  = _client.GetEntities <MobView>(ValidateMob);

            var views = new List <SimulationObjectView>();

            foreach (var r in resources)
            {
                views.Add(r);
            }
            //foreach (var h in hostiles) views.Add(h);

            var filteredViews = views.Where(view =>
            {
                if (view is HarvestableObjectView harvestable)
                {
                    var resourceType     = (ResourceType)Enum.Parse(typeof(ResourceType), harvestable.GetResourceType(), true);
                    var tier             = (Tier)harvestable.GetTier();
                    var enchantmentLevel = (EnchantmentLevel)harvestable.GetRareState();

                    var info = new GatherInformation(resourceType, tier, enchantmentLevel);

                    return(_gatherInformations[info]);
                }
                else
                {
                    return(false);
                }
            });

            target = filteredViews.OrderBy((view) =>
            {
                var playerPosition   = _localPlayerCharacterView.transform.position;
                var resourcePosition = view.transform.position;

                var score = (resourcePosition - playerPosition).sqrMagnitude;

                if (view is HarvestableObjectView harvestable)
                {
                    var rareState = harvestable.GetRareState();

                    if (harvestable.GetTier() >= 3)
                    {
                        score /= 2;
                    }
                    if (harvestable.GetCurrentCharges() == harvestable.GetMaxCharges())
                    {
                        score /= 2;
                    }
                    if (rareState > 0)
                    {
                        score /= rareState;
                    }
                }
                else if (view is MobView mob)
                {
                }

                var yDelta = Math.Abs(_landscape.GetLandscapeHeight(playerPosition.c()) - _landscape.GetLandscapeHeight(resourcePosition.c()));

                score += (yDelta * 10f);

                return((int)score);
            }).FirstOrDefault();

            if (target != null)
            {
                Core.Log($"Resource spotted: {target.name}");
            }

            return(target != default(SimulationObjectView));
        }
Пример #15
0
 public static SimulationObject GetSimulationObject(this SimulationObjectView view) => view.SimulationObject;
 public static bool TryFindPath(this LocalPlayerCharacterView instance, AStarPathfinder pathfinder, SimulationObjectView target,
                                StopFunction <Vector2> stopFunction, out List <Vector3> results)
 {
     return(instance.TryFindPath(pathfinder, target.transform.position, stopFunction, out results));
 }
Пример #17
0
        private void Search()
        {
            if (HandleAttackers())
            {
                return;
            }

            var isCurrentCluster = ObjectManager.GetInstance().GetCurrentCluster().GetName() == _selectedGatherCluster;
            var isHomeCluster    = ObjectManager.GetInstance().GetCurrentCluster().GetName() == TownClusterNames[_selectedTownClusterIndex];

            if (isCurrentCluster && _allowSiegeCampTreasure && CanUseSiegeCampTreasure && (_localPlayerCharacterView.GetLoadPercent() > _percentageForSiegeCampTreasure))
            {
                Core.Log("Start Seige Camp Treasure Routine");
                _state.Fire(Trigger.StartSiegeCampTreasure);
                return;
            }

            if (_localPlayerCharacterView.GetLoadPercent() > _percentageForBanking)
            {
                Core.Log("Over allowed Weight. Start Banking procedure.");
                _state.Fire(Trigger.Overweight);
                return;
            }

            if (_localPlayerCharacterView.GetLocalPlayerCharacter().HasAnyBrokenItem())
            {
                Core.Log("Damaged - Items fell below 10% durability. Head to Repair in home town");
                _state.Fire(Trigger.Damaged);
                return;
            }

            if (isHomeCluster)
            {
                if (_localPlayerCharacterView.GetLocalPlayerCharacter().HasAnyDamagedItem())
                {
                    Core.Log("We are in home town with damaged items. Fix them before going to harvest.");
                    _state.Fire(Trigger.Damaged);
                    return;
                }
            }

            if (!isCurrentCluster)
            {
                Worldmap worldmapInstance = GameGui.Instance.WorldMap;

                Core.Log("[Travel to target cluster]");
                _targetCluster = worldmapInstance.GetCluster(_selectedGatherCluster).Info;
                _state.Fire(Trigger.StartTravelling);
                return;
            }

            if (Loot())
            {
                return;
            }

            if (_currentTarget != null)
            {
                Core.Log("[Blacklisting target]");

                Blacklist(_currentTarget, TimeSpan.FromMinutes(0.5));

                _currentTarget         = null;
                _harvestPathingRequest = null;

                return;
            }

            if (IdentifiedTarget(out SimulationObjectView target))
            {
                Core.Log("[Checking Target]");

                _currentTarget = target;
            }

            if (_currentTarget != null && ValidateTarget(_currentTarget))
            {
                Core.Log("[Identified]");

                _changeGatheringPathRequest = null;
                _failedFindAttempts         = 0;
                _state.Fire(Trigger.DiscoveredResource);

                return;
            }
            else
            {
                if (HandlePathing(ref _changeGatheringPathRequest))
                {
                    return;
                }

                _failedFindAttempts++;
                if (_failedFindAttempts > MAXIMUM_FAIL_ATTEMPTS)
                {
                    Core.Log($"[Looking for fallback in {_gatheredSpots.Count} objects]");

                    //Remove all fallback points older than 1 hour
                    var entriesToRemove = _gatheredSpots.Where(kvp => !kvp.Value.HarvestDate.HasValue || kvp.Value.HarvestDate.Value.AddHours(1) < DateTime.UtcNow).ToArray();
                    foreach (var entry in entriesToRemove)
                    {
                        Core.Log($"[Removing {entry.Key} from fallback objects. Too old]");
                        _gatheredSpots.Remove(entry.Key);
                    }

                    var validEntries = _gatheredSpots.Where(kvp =>
                    {
                        var info = new GatherInformation(kvp.Value.ResourceType, kvp.Value.Tier, kvp.Value.EnchantmentLevel);
                        return(_gatherInformations[info]);
                    }).ToArray();

                    Core.Log($"[Found {validEntries.Length} valid fallback objects]");
                    if (validEntries.Length == 0)
                    {
                        return;
                    }

                    //Select a random fallback point
                    var spotToUse = validEntries[UnityEngine.Random.Range(0, validEntries.Length)];
                    var spot3d    = new Vector3(spotToUse.Key.GetX(), _landscape.GetTerrainHeight(spotToUse.Key, out RaycastHit hit), spotToUse.Key.GetY());
                    if (_localPlayerCharacterView.TryFindPath(new ClusterPathfinder(), spot3d, IsBlockedGathering, out List <Vector3> pathing))
                    {
                        Core.Log($"Falling back to {spot3d} which should hold {spotToUse.Value.ToString()}. Removing it from fallback objects.");
                        _changeGatheringPathRequest = new PositionPathingRequest(_localPlayerCharacterView, spot3d, pathing);
                    }
                    else
                    {
                        Core.Log($"No path to {spot3d} found. Removing it from fallback objects.");
                    }

                    _gatheredSpots.Remove(spotToUse.Key);
                    _failedFindAttempts = 0;
                }
            }
        }