示例#1
0
        public override void ApplyEffect(GameContext context, Actor executor, Pos2D pos)
        {
            var targets = context.Level.GetCellsInSquare(pos, 1).Where(c => executor.CanSee(c.Pos)).ToList();

            targets = targets.OrderBy(o => context.Randomizer.GetDouble()).ToList();

            // This shouldn't happen, but in the case where zero cells are visible, just do nothing in general
            if (!targets.Any())
            {
                if (executor.IsPlayer || context.CanPlayerSee(pos) || context.CanPlayerSee(executor.Pos))
                {
                    context.AddMessage($"{executor.Name} tries to use {Name} but had a targeting issue", ClientMessageType.Failure);
                }

                return;
            }

            if (executor.IsPlayer || context.CanPlayerSee(pos) || context.CanPlayerSee(executor.Pos))
            {
                context.AddMessage($"{executor.Name} fires a {Name}", ClientMessageType.Generic);
            }

            // Pick 3 random targets that are visible around the target cell and fire projectiles at them
            foreach (var target in targets.Take(Math.Max(3, targets.Count)))
            {
                if (executor.IsPlayer || context.CanPlayerSee(target.Pos))
                {
                    context.AddEffect(new ProjectileEffect(executor, target.Pos));
                }

                context.CombatManager.HandleExplosion(context, executor, target.Pos, 2, 1, DamageType.Normal);
            }
        }
示例#2
0
        /// <inheritdoc />
        public override bool OnActorAttemptedEnter(GameContext context, Actor actor)
        {
            if (actor.IsPlayer)
            {
                if (IsCorrupted)
                {
                    context.AddMessage($"The {Name} is corrupt and cannot be accessed.", ClientMessageType.Failure);
                }
                else
                {
                    context.AddMessage($"The {Name} does not respond to your queries.", ClientMessageType.Generic);
                }
            }

            return(false);
        }
示例#3
0
        /// <inheritdoc />
        public override bool OnActorAttemptedEnter(GameContext context, Actor actor)
        {
            if (actor.IsPlayer)
            {
                if (IsCorrupted)
                {
                    context.AddMessage($"The {Name} has been corrupted and spins chaotically.", ClientMessageType.Failure);
                }
                else
                {
                    context.AddMessage($"The {Name} spins and whirs, oblivious to your concerns.", ClientMessageType.Generic);
                }
            }

            return(false);
        }
示例#4
0
        private bool HandleCommandActivation(GameContext context, Actor executor, Pos2D pos)
        {
            executor.Operations -= ActivationCost;

            if (ActivationType == CommandActivationType.Active)
            {
                if (executor.IsPlayer)
                {
                    context.AddMessage($"{Name} activated", ClientMessageType.Generic);
                    context.AddEffect(new ActivatedEffect(executor, Name));
                }

                OnActivated(context, executor, pos);
            }
            else
            {
                if (!IsSilent)
                {
                    context.AddEffect(new TauntEffect(executor, $"{Name}!"));
                }

                ApplyEffect(context, executor, pos);
            }

            return(ActivationType == CommandActivationType.Active);
        }
示例#5
0
        public override void ApplyEffect(GameContext context, Actor executor, Pos2D pos)
        {
            if (executor.IsPlayer || context.CanPlayerSee(executor.Pos) || context.CanPlayerSee(pos))
            {
                context.AddMessage($"{executor.Name} cleanses an area of corruption.", ClientMessageType.Generic);
                context.AddEffect(new ProjectileEffect(executor, pos));
            }

            const int strength = 1;

            var cells = context.Level.GetCellsInSquare(pos, 2);

            foreach (var cell in cells)
            {
                var isCellVisible = context.CanPlayerSee(cell.Pos);

                // Add the effect for the cell
                if (isCellVisible && cell.Corruption > 0)
                {
                    context.AddEffect(new CleanseEffect(cell.Pos, strength));
                }

                // Reduce base corruption
                cell.Corruption -= strength;

                // Also cleanse any objects on the cell
                foreach (var obj in cell.Objects.Where(o => o.IsCorruptable || (o.Team == Alignment.Bug || o.Team == Alignment.Virus)).ToList())
                {
                    obj.ApplyCorruptionDamage(context, executor, -strength);
                }
            }
        }
示例#6
0
        public override void MaintainActiveEffects(GameContext context)
        {
            base.MaintainActiveEffects(context);

            foreach (var cmd in HotbarCommands.Where(c => c?.Command != null && c.IsActive &&
                                                     c.Command.ActivationType == CommandActivationType.Active))
            {
                // Deactivate the command if it can't be paid for
                if (cmd.Command.MaintenanceCost > Operations)
                {
                    if (IsPlayer)
                    {
                        context.AddMessage($"{cmd.Command.Name} deactivates due to lack of available operations", ClientMessageType.Failure);
                        context.AddEffect(new DeactivatedEffect(this, cmd.Command.Name));
                    }

                    cmd.IsActive = false;
                    continue;
                }

                AdjustOperationsPoints(-cmd.Command.MaintenanceCost);

                cmd.Command.ApplyEffect(context, this, Pos);
            }
        }
示例#7
0
        public override void ApplyEffect(GameContext context, Actor executor, Pos2D pos)
        {
            var candidates = new List <Actor>();

            foreach (var cellPos in executor.VisibleCells)
            {
                var cell = context.Level.GetCell(cellPos);

                if (cell?.Actor != null && cell.Actor != executor && cell.Actor.Team != executor.Team)
                {
                    candidates.Add(cell.Actor);
                }
            }

            if (!candidates.Any())
            {
                if (executor.IsPlayer || context.CanPlayerSee(executor.Pos))
                {
                    context.AddMessage($"{executor.Name} attempts to {Name} but no targets are visible", ClientMessageType.Failure);
                }

                return;
            }

            if (executor.IsPlayer || context.CanPlayerSee(executor.Pos))
            {
                context.AddMessage($"{executor.Name} barrages", ClientMessageType.Generic);
            }

            // Order randomly
            candidates = candidates.OrderBy(c => context.Randomizer.GetDouble()).ToList();

            // Affect up to 6 targets randomly
            var targets = candidates.Take(Math.Min(6, candidates.Count)).ToList();

            foreach (var target in targets)
            {
                if (executor.IsPlayer || context.CanPlayerSee(target.Pos) ||
                    context.CanPlayerSee(executor.Pos))
                {
                    context.AddEffect(new ProjectileEffect(executor, target.Pos));
                }

                context.CombatManager.HandleExplosion(context, executor, target.Pos, 2, 1, DamageType.Normal);
            }
        }
示例#8
0
        public override bool OnActorAttemptedEnter(GameContext context, Actor actor)
        {
            if (actor.IsPlayer)
            {
                context.AddMessage("You can't do that; nobody implemented swimming!", ClientMessageType.Failure);
            }

            return(false);
        }
示例#9
0
        /// <inheritdoc />
        public override bool OnActorAttemptedEnter(GameContext context, Actor actor)
        {
            if (actor.IsPlayer)
            {
                context.AddMessage("You can't turn back; The network topology doesn't allow for it.", ClientMessageType.Failure);
            }

            return(false);
        }
示例#10
0
        public override void ApplyEffect(GameContext context, Actor executor, Pos2D pos)
        {
            if (executor.IsPlayer || context.CanPlayerSee(executor.Pos) || context.CanPlayerSee(pos))
            {
                context.AddMessage($"{executor.Name} teleports", ClientMessageType.Generic);
            }

            context.TeleportActor(executor, pos);
        }
示例#11
0
        public override void ApplyEffect(GameContext context, Actor executor, Pos2D pos)
        {
            var strength = context.Randomizer.GetInt(2, 4);

            if (executor.IsPlayer || context.CanPlayerSee(executor.Pos))
            {
                context.AddMessage($"{executor.Name} overloads", ClientMessageType.Generic);
            }

            context.CombatManager.HandleExplosion(context, executor, executor.Pos, strength, 4, DamageType.Normal);
        }
示例#12
0
        public override void ApplyEffect(GameContext context, Actor executor, Pos2D pos)
        {
            // Do nothing
            if (executor.IsPlayer || context.CanPlayerSee(pos))
            {
                context.AddEffect(new ProjectileEffect(executor, pos));
            }

            context.AddMessage($"{executor.Name} infects a small area.", ClientMessageType.Generic);
            context.CombatManager.HandleExplosion(context, executor, pos, 1, 1, DamageType.Corruption);
        }
示例#13
0
        public bool AttemptPickupItem(GameContext context, GameObjectBase item)
        {
            // TODO: this won't work once we have more items that can be picked up
            CommandPickup commandPickup = (CommandPickup)item;

            if (commandPickup.CommandId == null)
            {
                context.AddError($"{Name} attempts to pick up the command but it vanishes into the void");
                return(true);
            }

            var command = CommandFactory.CreateCommand(commandPickup.CommandId);

            if (item.IsCorrupted)
            {
                context.AddMessage($"{Name} picks up the corrupted item and is struck by a virus!", ClientMessageType.Failure);
                var message = context.CombatManager.HurtObject(context, item, this, 3, "infects", DamageType.Combination);
                context.AddMessage(message, ClientMessageType.Failure);
                return(true);
            }

            int index = HotbarCommands.IndexOf(null);

            if (index >= 0)
            {
                HotbarCommands[index] = CommandFactory.CreateCommandReference(command);
                context.AddMessage($"{Name} picks up {command.Name}", ClientMessageType.Success);
                return(true);
            }

            index = StoredCommands.IndexOf(null);
            if (index >= 0)
            {
                StoredCommands[index] = CommandFactory.CreateCommandReference(command);
                context.AddMessage($"{Name} picks up {command.Name} and stores it", ClientMessageType.Success);
                return(true);
            }

            context.AddMessage($"{Name} does not have enough free space to pick up {command.Name}", ClientMessageType.Failure);
            return(false);
        }
示例#14
0
        private bool DeactivateCommand(GameContext context, Actor executor, Pos2D pos)
        {
            if (executor.IsPlayer)
            {
                context.AddMessage($"{Name} deactivated", ClientMessageType.Generic);
                context.AddEffect(new DeactivatedEffect(executor, Name));
            }

            OnDeactivated(context, executor, pos);

            return(false);
        }
示例#15
0
        public override void ApplyCorruptionDamage(GameContext context, GameObjectBase source, int damage)
        {
            if (damage >= 0)
            {
                return;
            }

            var message = context.CombatManager.HurtObject(context, source, this, -damage, "cleanses", DamageType.Normal);

            if (context.CanPlayerSee(Pos))
            {
                context.AddMessage(message, ClientMessageType.Generic);
            }
        }
示例#16
0
        private bool HandleInsufficientOperations(GameContext context, Actor executor)
        {
            if (executor.IsPlayer)
            {
                string opsPluralString = ActivationCost == 1 ? "operation" : "operations";
                string message         = executor.IsPlayer
                    ? $"You must have {ActivationCost} free {opsPluralString} to use {Name}"
                    : $"{executor.Name} tries to use {Name} but doesn't have enough free operations";

                context.AddMessage(message, ClientMessageType.Failure);
            }

            return(false);
        }
示例#17
0
        public override void ApplyEffect(GameContext context, Actor executor, Pos2D pos)
        {
            if (!executor.IsPlayer)
            {
                context.AddError($"{executor.Name} tries to invoke the {Name} command but does not have permission.");
                return;
            }

            context.Level.MarkedPos = executor.Pos;

            if (executor.IsPlayer || context.CanPlayerSee(executor.Pos))
            {
                context.AddMessage($"{executor.Name} marks their current position.", ClientMessageType.Success);
                context.AddEffect(new CellMarkedEffect(executor.Pos));
            }
        }
示例#18
0
        /// <inheritdoc />
        public override bool OnActorAttemptedEnter(GameContext context, Actor actor)
        {
            if (IsOpen ||
                actor.Team == Alignment.SystemCore ||
                actor.Team == Alignment.SystemSecurity ||
                actor.Team == Alignment.SystemAntiVirus)
            {
                context.MoveObject(actor, Pos);
                return(true);
            }

            if (actor.IsPlayer)
            {
                context.AddMessage("You must capture all cores on the system before you can breach the firewall.", ClientMessageType.Failure);
            }

            return(false);
        }
示例#19
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="context">The current command context.</param>
        /// <param name="executor">The actor executing the command.</param>
        /// <param name="pos">The targeted position for the command. For non-targeted commands, this will be <paramref name="executor"/>'s current position.</param>
        /// <param name="isCurrentlyActive">Whether or not the command is currently active</param>
        public bool Execute(GameContext context, Actor executor, Pos2D pos, bool isCurrentlyActive)
        {
            switch (ActivationType)
            {
            case CommandActivationType.Active when isCurrentlyActive:
                return(DeactivateCommand(context, executor, pos));

            // Don't let the player target things they can't see
            case CommandActivationType.Targeted when !executor.CanSee(pos):
                if (executor.IsPlayer)
                {
                    context.AddMessage($"{executor.Name} tries to {Name} but cannot see the target",
                                       ClientMessageType.Failure);
                }

                return(false);

            default:
                return(executor.Operations >= ActivationCost
                        ? HandleCommandActivation(context, executor, pos)
                        : HandleInsufficientOperations(context, executor));
            }
        }
示例#20
0
        public override void ApplyEffect(GameContext context, Actor executor, Pos2D pos)
        {
            // Figure out how much to add without going over the maximum stability
            int amount = Math.Min(executor.MaxStability - executor.Stability, Strength);

            // Actually add
            executor.Stability += amount;

            // Display the message to the client, rendering things differently if the player did them.
            if (executor.IsPlayer || context.CanPlayerSee(executor.Pos))
            {
                var messageType = executor.IsPlayer ? ClientMessageType.Success : ClientMessageType.Generic;
                var message     = amount == 0
                    ? $"{executor.Name} stabilizes"
                    : $"{executor.Name} stabilizes, restoring {amount} stability";

                context.AddMessage(message, messageType);
                if (amount > 0)
                {
                    context.AddEffect(new StabilityRestoreEffect(executor, amount));
                }
            }
        }