/// <summary>
        /// Remove metalOre from drawing list
        /// </summary>
        /// <param name="metalOre"></param>
        private static void RemoveMetalOreEntityFromDrawingList(GameObjectBase metalOre)
        {
            EntityInfo entityInfo = new EntityInfo();
            long       key        = metalOre.InitialAddress;

            _metalOreEntities.TryRemove(key, out entityInfo);
        }
        /// <summary>
        /// Remove hemp from drawing list
        /// </summary>
        /// <param name="metalOre"></param>
        private static void RemoveHempNodeFromDrawingList(GameObjectBase hemp)
        {
            EntityInfo entityInfo = new EntityInfo();
            long       key        = hemp.InitialAddress;

            _hempNodes.TryRemove(key, out entityInfo);
        }
        /// <summary>
        /// Remove animal entity from drawing list
        /// </summary>
        /// <param name="metalOre"></param>
        private static void RemoveAnimalEntityFromDrawingList(GameObjectBase animal)
        {
            EntityInfo entityInfo = new EntityInfo();
            long       key        = animal.InitialAddress;

            _animalEntities.TryRemove(key, out entityInfo);
        }
Beispiel #4
0
        public static float GetCombatMagicResist(GameObjectBase attacker, GameObjectBase target)
        {
            var magicResist = target.UnitStats.MagicResist * attacker.UnitStats.MagicPercentPenetration;

            magicResist -= attacker.UnitStats.FlatMagicPenetration;
            return(magicResist);
        }
        /// <summary>
        /// Remove sulfur from drawing list
        /// </summary>
        /// <param name="sulfur"></param>
        private static void RemoveSulfurEntityFromDrawingList(GameObjectBase sulfur)
        {
            EntityInfo entityInfo = new EntityInfo();
            long       key        = sulfur.InitialAddress;

            _sulfurOreEntities.TryRemove(key, out entityInfo);
        }
Beispiel #6
0
        /// <summary>
        /// Remove loot entity from drawing list
        /// </summary>
        /// <param name="metalOre"></param>
        private static void RemoveMilitaryCrateFromDrawingList(GameObjectBase lootEntity)
        {
            EntityInfo entityInfo = new EntityInfo();
            long       key        = lootEntity.InitialAddress;

            _militaryCrates.TryRemove(key, out entityInfo);
        }
Beispiel #7
0
        public static float GetCombatArmor(GameObjectBase attacker, GameObjectBase target)
        {
            var armor = target?.Armor ?? 1 * attacker.UnitStats.PercentBonusArmorPenetration;

            armor -= attacker.UnitStats.PhysicalLethality;
            return(armor);
        }
Beispiel #8
0
        /// <summary>
        /// Remove loot entity from drawing list
        /// </summary>
        /// <param name="metalOre"></param>
        private static void RemoveStorageContainerFromDrawingList(GameObjectBase storageEntity)
        {
            EntityInfo entityInfo = new EntityInfo();
            long       key        = storageEntity.InitialAddress;

            _storageContainers.TryRemove(key, out entityInfo);
        }
Beispiel #9
0
        /// <summary>
        /// Remove loot entity from drawing list
        /// </summary>
        /// <param name="metalOre"></param>
        private static void RemoveToolCupboardFromDrawingList(GameObjectBase toolCupboard)
        {
            EntityInfo entityInfo = new EntityInfo();
            long       key        = toolCupboard.InitialAddress;

            _toolCupboards.TryRemove(key, out entityInfo);
        }
Beispiel #10
0
 public MissedEffect([NotNull] GameObjectBase source) : base(source)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
 }
        private void ApplyDamageToActor(GameContext context,
                                        GameObjectBase attacker,
                                        GameObjectBase defender,
                                        string verb,
                                        DamageType damageType)
        {
            int damage = CalculateDamage(context, attacker, defender, verb);

            // If it was ineffective, handle that early and apply special effects as needed
            if (damage <= 0)
            {
                ShowNoDamageMessage(context, attacker, defender, verb);
                return;
            }

            // Apply the damage and get a result
            var message = HurtObject(context, attacker, defender, damage, verb, damageType);

            // Only add this message if it occurs somewhere within the player's line of sight or involves the player
            if (attacker.IsPlayer || defender.IsPlayer || context.CanPlayerSee(attacker) || context.CanPlayerSee(defender))
            {
                var messageType = DetermineCombatMessageType(damage, defender.IsDead);
                context.AddMessage(message, messageType);
            }
        }
        /// <summary>
        /// Player address get reused so we have to validate a player before we continue updating their information that gets drawn.
        /// Invalid players are removed from all lists until added again
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        private static bool ValidatePlayer(GameObjectBase player)
        {
            /* Address no longer used to store player struct */
            if (player.Tag != 6)
            {
                RemoveActivePlayerEntityFromDrawingList(player);
                RemoveFromSleeperDrawingList(player);
                _gameObjectManager.Players.TryRemove(player.SteamID, out GameObjectBase p);
                return(false);
            }
            /* Dead player */
            if (player.Health == 0)
            {
                try
                {
                    RemoveActivePlayerEntityFromDrawingList(player);
                    RemoveFromSleeperDrawingList(player);
                    _gameObjectManager.Players.TryRemove(player.SteamID, out GameObjectBase p);
                }
                catch (Exception)
                {
                    return(false);
                }

                return(false);
            }

            return(true);
        }
Beispiel #13
0
 public ActorDamagedEventArgs(GameObjectBase attacker, GameObjectBase defender, int damage, DamageType damageType)
 {
     Attacker   = attacker;
     Defender   = defender;
     Damage     = damage;
     DamageType = damageType;
 }
Beispiel #14
0
        public void MoveObject([NotNull] GameObjectBase obj, Pos2D newPos)
        {
            var oldPos = obj.Pos;

            Level.MoveObject(obj, newPos);

            AddMessage(new MovedMessage(obj, oldPos, newPos));
        }
        /// <summary>
        /// Initializes a new instance of the ChaseCamera class.
        /// </summary>
        /// <param name="chaseTarget">The object being chased by the camera. This value can be null.</param>
        public ChaseCamera(GameObjectBase chaseTarget)
            : base(Vector3.Zero, chaseTarget != null ? chaseTarget.Position : Vector3.Zero)
        {
            this.ChaseTarget = chaseTarget;

            this.CameraDistance = 15;
            this.HeightDifference = 6;
        }
Beispiel #16
0
        public static float GetArmorMod(GameObjectBase attacker, GameObjectBase target)
        {
            var armor     = GetCombatArmor(attacker, target);
            var damageMod = armor > 0
                                ? 100 / (100 + armor)
                                : 2 - 100 / (100 + armor);

            return(damageMod);
        }
Beispiel #17
0
        public static float GetMagicResistMod(GameObjectBase attacker, GameObjectBase target)
        {
            var magicResist = GetCombatMagicResist(attacker, target);
            var damageMod   = magicResist > 0
                                ? 100 / (100 + magicResist)
                                : 2 - 100 / (100 + magicResist);

            return(damageMod);
        }
Beispiel #18
0
        /// <summary>
        /// Removes any instance of <paramref name="obj"/> from the level.
        /// </summary>
        /// <param name="obj">The object to remove.</param>
        public void RemoveObject(GameObjectBase obj)
        {
            foreach (var cell in _cells.Values)
            {
                cell.RemoveObject(obj);
            }

            ClearVisibilityCache();
        }
        private static int CalculateDamageResistance(GameObjectBase gameObject, DamageType damageType, IRandomization random)
        {
            if (damageType != DamageType.Normal)
            {
                return(0);
            }

            return(gameObject is Actor actor?CalculateDefenseStrength(actor, random) : 0);
        }
Beispiel #20
0
        public override void OnDestroyed(GameContext context, GameObjectBase attacker)
        {
            base.OnDestroyed(context, attacker);

            if (!IsOpen)
            {
                Open(context, attacker);
            }
        }
Beispiel #21
0
        public SoundEffect([NotNull] GameObjectBase source, SoundEffects soundType) : base(source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            Sound = soundType;
        }
        public static Rectangle GetBoundingRectangle(ScreenBase screen, GameObjectBase gameObject, GameContext gameContext)
        {
            var startX = (int)((screen.OriginX + gameObject.Column) * gameContext.GameObjectWidth);
            var startY = (int)((screen.OriginY + gameObject.Row) * gameContext.GameObjectHeight);
            var width  = (int)gameContext.GameObjectWidth * gameObject.ColumnSpan;
            var height = (int)gameContext.GameObjectHeight * gameObject.RowSpan;

            return(new Rectangle(startX, startY, width, height));
        }
 private static void ShowNoDamageMessage(GameContext context,
                                         GameObjectBase attacker,
                                         GameObjectBase defender,
                                         string verb)
 {
     context.AddEffect(new NoDamageEffect(defender));
     context.AddMessage(defender.IsInvulnerable
         ? $"{attacker.Name} {verb} {defender.Name} but it is impervious to all damage."
         : $"{attacker.Name} {verb} {defender.Name} but deals no damage.", DetermineCombatMessageType(0, false));
 }
Beispiel #24
0
        public CreatedMessage AddObject([NotNull] GameObjectBase obj)
        {
            Level.AddObject(obj);

            var message = new CreatedMessage(obj);

            AddMessage(message);

            return(message);
        }
Beispiel #25
0
        /// <summary>
        /// Adds a game object to the level.
        /// </summary>
        /// <param name="gameObject">The game object.</param>
        /// <exception cref="InvalidOperationException">Thrown if the specified object's position does not correspond with a known cell</exception>
        public void AddObject(GameObjectBase gameObject)
        {
            var cell = GetCell(gameObject.Pos);

            if (cell == null)
            {
                throw new InvalidOperationException($"Could not find a cell at {gameObject.Pos.ToString()} to add an object to");
            }

            cell.AddObject(gameObject);
        }
Beispiel #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameObject"></param>
        /// <returns></returns>
        public static bool IsToolCupboard(this GameObjectBase gameObject)
        {
            var entityName = gameObject.EntityName.ToUpper();

            if ((entityName.Contains("TOOL") && entityName.Contains("CUPBOARD")))
            {
                return(true);
            }

            return(false);
        }
Beispiel #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameObject"></param>
        /// <returns></returns>
        public static bool IsHempNode(this GameObjectBase gameObject)
        {
            var entityName = gameObject.EntityName.ToUpper();

            if ((entityName.Contains("HEMP-COLLECTABLE")))
            {
                return(true);
            }

            return(false);
        }
Beispiel #28
0
        /// <summary>
        /// Determine if crate is elite crate
        /// </summary>
        public static bool IsEliteCrate(this GameObjectBase gameObject)
        {
            var entityName = gameObject.EntityName.ToUpper();

            if (entityName.Contains("CRATE_ELITE")) /* Elite military crates */
            {
                return(true);
            }

            return(false);
        }
Beispiel #29
0
        public void AddObject(GameObjectBase gameObject)
        {
            if (!_cells.ContainsKey(gameObject.Pos))
            {
                _cells[gameObject.Pos] = new GameCell();
            }

            var cell = _cells[gameObject.Pos];

            cell.AddObject(gameObject);
        }
Beispiel #30
0
        public void RemoveObject([NotNull] GameObjectBase gameObj)
        {
            if (gameObj == null)
            {
                throw new ArgumentNullException(nameof(gameObj));
            }

            Level.RemoveObject(gameObj);

            AddMessage(new DestroyedMessage(gameObj));
        }
Beispiel #31
0
        public void UpdateFrom(ObjectUpdatedMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            Source = message.Source;

            // Notify all properties changed
            OnPropertyChanged(string.Empty);
        }
Beispiel #32
0
        /// <summary>
        /// Checks to see if any of the bounding spheres of the specified meshes collide.
        /// </summary>
        /// <param name="gameObject1">The first game object in the collision check.</param>
        /// <param name="gameObject2">The second game object in the collision check.</param>
        /// <returns>Whether the models collided.</returns>
        public static bool Colliding(GameObjectBase gameObject1, GameObjectBase gameObject2)
        {
            if (gameObject1 == gameObject2 || (!gameObject1.Collides || !gameObject2.Collides) || (gameObject1 is Player && gameObject2 is Player))
            {
                return false;
            }

            for (int i = 0; i < gameObject1.Model.Meshes.Count; i++)
            {
                BoundingSphere sphere1 = new BoundingSphere(gameObject1.Model.Meshes[i].BoundingSphere.Center + gameObject1.Position, gameObject1.Model.Meshes[i].BoundingSphere.Radius);

                for (int j = 0; j < gameObject2.Model.Meshes.Count; j++)
                {
                    BoundingSphere sphere2 = new BoundingSphere(gameObject2.Model.Meshes[j].BoundingSphere.Center + gameObject2.Position, gameObject2.Model.Meshes[j].BoundingSphere.Radius);

                    if (sphere1.Intersects(sphere2))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
Beispiel #33
0
 public PositionChangeRequest(GameObjectBase gameObject, Vector2 position)
 {
     GameObject = gameObject;
     Position = position;
 }
Beispiel #34
0
 public GameObjectAdded(GameObjectBase gameObject)
 {
     GameObject = gameObject;
 }
Beispiel #35
0
        public ICollision CalculateCollision(GameObjectBase gameObject, TickTime tickTime)
        {
            if (gameObject.Body.Velocity == Vector2.Zero)
                return null;

            if (gameObject is GolfBall)
                return CalculateCollision((GolfBall) gameObject, tickTime);

            return null;
        }
Beispiel #36
0
 public RemoveForceRequest(GameObjectBase gameObject, IForce force)
 {
     GameObject = gameObject;
     Force = force;
 }
Beispiel #37
0
 public ApplyImpulseRequest(GameObjectBase gameObject, Vector2 impulse)
 {
     GameObject = gameObject;
     Impulse = impulse;
 }
Beispiel #38
0
 public AddGameObjectRequest(GameObjectBase gameObject)
 {
     GameObject = gameObject;
 }