Exemplo n.º 1
0
 public void CheckIsBattleOver()
 {
     QueuedActions.ImmediateAction("CheckIsBattleOver", () =>
     {
         BattleRules.CheckIsBattleOverAndIfSoSwitchScenes();
     });
 }
Exemplo n.º 2
0
 // Called by the game to create an instance of this event.
 // Note: This constructor should not be available in the API.
 internal BattleStartedEvent(BattleRules battleRules, int robotsCount, bool isReplay)
     : base()
 {
     this.battleRules = battleRules;
     this.isReplay = isReplay;
     this.robotsCount = robotsCount;
 }
    public static void CheckAndRegisterDeath(AbstractBattleUnit unit, AbstractBattleUnit nullableUnitThatKilledMe, AbstractCard cardUsedIfAny)
    {
        if (unit.HasDied)
        {
            /// stopping this from triggering more than once on a unit
            return;
        }

        if (unit.CurrentHp <= 0)
        {
            unit.HasDied = true;
            ActionManager.Instance.TriggerUnitKilledFeedback(unit);

            foreach (var effect in unit.StatusEffects)
            {
                effect.OnDeath(nullableUnitThatKilledMe, cardUsedIfAny);
            }

            BattleRules.TriggerProc(new CharacterDeathProc {
                CharacterDead = unit
            });

            foreach (var card in GameState.Instance.Deck.TotalDeckList)
            {
                if (card.Owner == unit)
                {
                    // we always exhaust all cards owned by dead people.
                    ActionManager.Instance.ExhaustCard(card);
                }
            }
        }
    }
Exemplo n.º 4
0
 internal void CreateCardToBattleDeckDiscardPile(AbstractCard abstractCard,
                                                 AbstractBattleUnit owner      = null,
                                                 CardCreationLocation location = CardCreationLocation.SHUFFLE,
                                                 QueueingType queueingType     = QueueingType.TO_BACK)
 {
     Require.NotNull(abstractCard);
     abstractCard.Owner = owner;
     QueuedActions.ImmediateAction("CreateCardToBattleDeckDiscardPile", () =>
     {
         BattleRules.MarkCreatedCard(abstractCard, owner);
         if (location == CardCreationLocation.BOTTOM)
         {
             ServiceLocator.GameState().Deck.DiscardPile.Add(abstractCard);
         }
         else if (location == CardCreationLocation.TOP)
         {
             ServiceLocator.GameState().Deck.DiscardPile.AddToFront(abstractCard);
         }
         else if (location == CardCreationLocation.SHUFFLE)
         {
             ServiceLocator.GameState().Deck.DiscardPile.InsertIntoRandomLocation(abstractCard);
         }
         else
         {
             throw new Exception("gotta select a location");
         }
     }, queueingType);
 }
Exemplo n.º 5
0
 // Called by the game to create an instance of this event.
 // Note: This constructor should not be available in the API.
 internal BattleStartedEvent(BattleRules battleRules, int robotsCount, bool isReplay)
     : base()
 {
     this.battleRules = battleRules;
     this.isReplay    = isReplay;
     this.robotsCount = robotsCount;
 }
Exemplo n.º 6
0
 public RobotStatics(string robocodeVersion, bool isJuniorRobot, bool isInteractiveRobot, bool isPaintRobot, bool isAdvancedRobot,
                     bool isTeamRobot, bool isTeamLeader, bool isDroid, bool isSentryRobot, string name, string shortName,
                     string veryShortName, string fullClassName, string shortClassName, BattleRules battleRules,
                     string[] teammates, string teamName, int index, int contestantIndex)
 {
     this.robocodeVersion    = robocodeVersion;
     this.isJuniorRobot      = isJuniorRobot;
     this.isAdvancedRobot    = isAdvancedRobot;
     this.isTeamRobot        = isTeamRobot;
     this.isDroid            = isDroid;
     this.isSentryRobot      = isSentryRobot;
     this.isInteractiveRobot = isInteractiveRobot;
     this.isPaintRobot       = isPaintRobot;
     this.isTeamLeader       = isTeamLeader;
     this.name            = name;
     this.shortName       = shortName;
     this.veryShortName   = veryShortName;
     this.fullClassName   = fullClassName;
     this.shortClassName  = shortClassName;
     this.battleRules     = battleRules;
     this.teammates       = teammates;
     this.teamName        = teamName;
     this.index           = index;
     this.contestantIndex = contestantIndex;
 }
Exemplo n.º 7
0
            public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
            {
                bool        isJuniorRobot      = serializer.deserializeBoolean(buffer);
                bool        isInteractiveRobot = serializer.deserializeBoolean(buffer);
                bool        isPaintRobot       = serializer.deserializeBoolean(buffer);
                bool        isAdvancedRobot    = serializer.deserializeBoolean(buffer);
                bool        isTeamRobot        = serializer.deserializeBoolean(buffer);
                bool        isTeamLeader       = serializer.deserializeBoolean(buffer);
                bool        isDroid            = serializer.deserializeBoolean(buffer);
                string      name           = serializer.deserializeString(buffer);
                string      shortName      = serializer.deserializeString(buffer);
                string      veryShortName  = serializer.deserializeString(buffer);
                string      fullClassName  = serializer.deserializeString(buffer);
                string      shortClassName = serializer.deserializeString(buffer);
                BattleRules battleRules    = HiddenAccessN.createRules(
                    serializer.deserializeInt(buffer),
                    serializer.deserializeInt(buffer),
                    serializer.deserializeInt(buffer),
                    serializer.deserializeDouble(buffer),
                    serializer.deserializeLong(buffer)
                    );

                var    teammates = new List <string>();
                object item      = serializer.deserializeString(buffer);

                while (item != null)
                {
                    if (item is string)
                    {
                        teammates.Add((string)item);
                    }
                    item = serializer.deserializeString(buffer);
                }

                string teamName        = serializer.deserializeString(buffer);
                int    index           = serializer.deserializeInt(buffer);
                int    contestantIndex = serializer.deserializeInt(buffer);


                return(new RobotStatics(
                           isJuniorRobot,
                           isInteractiveRobot,
                           isPaintRobot,
                           isAdvancedRobot,
                           isTeamRobot,
                           isTeamLeader,
                           isDroid,
                           name,
                           shortName,
                           veryShortName,
                           fullClassName,
                           shortClassName,
                           battleRules,
                           teammates.ToArray(),
                           teamName,
                           index,
                           contestantIndex
                           ));
            }
Exemplo n.º 8
0
 public void KillUnit(AbstractBattleUnit unit)
 {
     QueuedActions.ImmediateAction("KillUnit", () =>
     {
         unit.CurrentHp = 0;
         BattleRules.CheckAndRegisterDeath(unit, null, null);
     });
 }
    public void Slay(AbstractCard damageSource, AbstractBattleUnit target)
    {
        var slew = SlayInner(damageSource, target);

        if (slew)
        {
            BattleRules.TriggerProc(new LethalTriggerProc());
        }
    }
 public static void Sly(this AbstractCard card, Action thingToDo)
 {
     if (state.Deck.Hand.Count < 3)
     {
         thingToDo();
         BattleRules.TriggerProc(new SlyProc {
             TriggeringCardIfAny = card
         });
     }
 }
 public static void Inferno(this AbstractCard card, Action thingToDo)
 {
     var burningEnemy = state.EnemyUnitsInBattle.Any(enemy => !enemy.IsDead && enemy.HasStatusEffect <BurningStatusEffect>());
     {
         thingToDo();
         BattleRules.TriggerProc(new InfernoProc {
             TriggeringCardIfAny = card
         });
     }
 }
Exemplo n.º 12
0
    private string GetDisplayedRetaliateDamage()
    {
        if (OwnerUnit == null)
        {
            return("");
        }
        var damageToReturn = BattleRules.GetAnticipatedDamageToUnit(OwnerUnit, null, 5, true, null);

        return($"[Will deal {damageToReturn} per hit before enemy modifiers]");
    }
Exemplo n.º 13
0
 public void ApplyDefense(AbstractBattleUnit target, AbstractBattleUnit source, int baseQuantity)
 {
     QueuedActions.ImmediateAction("ApplyDefense", () =>
     {
         target.CurrentBlock += BattleRules.GetDefenseApplied(source, target, baseQuantity);
         if (target.CurrentBlock < 0)
         {
             target.CurrentBlock = 0;
         }
     });
 }
Exemplo n.º 14
0
 public override CanPlayCardQueryResult CanPlayInner(AbstractBattleUnit target)
 {
     if (BattleRules.IsEnemyEligibleForTaunting(target, this.Owner))
     {
         return(CanPlayCardQueryResult.CanPlay());
     }
     else
     {
         return(CanPlayCardQueryResult.CannotPlay("Taunted units must be attacking exactly one" +
                                                  " target who is not the taunting character."));
     }
 }
        public static void Brute(this AbstractCard card, Action thingToDo)
        {
            var cost3Card = state.Deck.Hand.FirstOrDefault(c => c.BaseEnergyCost() == 3);

            if (cost3Card != null)
            {
                thingToDo();
                BattleRules.TriggerProc(new BruteProc {
                    TriggeringCardIfAny = card
                });
            }
        }
Exemplo n.º 16
0
    public override void OnStruck(AbstractBattleUnit unitStriking, AbstractCard cardUsedIfAny, int totalDamageTaken)
    {
        if (Stacks <= 0)
        {
            return;
        }
        var damageToReturn = BattleRules.GetAnticipatedDamageToUnit(OwnerUnit, unitStriking, 5, true, null);
        var enhancerStacks = unitStriking.GetStatusEffect <GentleDiscouragementStatusEffect>()?.Stacks ?? 0;

        action().DamageUnitNonAttack(unitStriking, null, damageToReturn + enhancerStacks);
        Stacks--;
    }
Exemplo n.º 17
0
 public void ExhaustCard(AbstractCard protoCard, QueueingType queueingType = QueueingType.TO_BACK)
 {
     QueuedActions.DelayedActionWithCustomTrigger("ExhaustCard", () => {
         gameState.Deck.MoveCardToPile(protoCard, CardPosition.EXPENDED);
         ServiceLocator.GetCardAnimationManager().DisappearCard(protoCard, assumedToExistInHand: false, callbackWhenFinished: () =>
         {
             IsCurrentActionFinished = true;
         });
         BattleRules.TriggerProc(new ExhaustedCardProc {
             TriggeringCardIfAny = protoCard
         });
     }, queueingType);
 }
        public static void Sacrifice(this AbstractCard card, Action thingToDo)
        {
            var sacrificableCard = state.Deck.Hand.FirstOrDefault(item => item != card);

            if (sacrificableCard != null)
            {
                sacrificableCard.Action_Exhaust();
                action.ApplyStress(sacrificableCard.Owner, 6);
                BattleRules.TriggerProc(new SacrificeProc {
                    TriggeringCardIfAny = card
                });
                thingToDo();
            }
        }
        public static void Liquidate(this AbstractCard card, Action thingToDo)
        {
            var firstRareCard = state.Deck.Hand.FirstOrDefault(item => item.Rarity == Rarity.RARE && item != card);

            if (firstRareCard != null)
            {
                thingToDo();

                action.ExhaustCard(firstRareCard);
                BattleRules.TriggerProc(new LiquidateProc {
                    TriggeringCardIfAny = card
                });
            }
        }
Exemplo n.º 20
0
        public BattleState(BattleRules battleRules, EntityState entity1, EntityState entity2)
        {
            BattleRules   = battleRules;
            Tags          = new TagCollection(this);
            m_entity1     = entity1;
            m_entity2     = entity2;
            m_nextActions = new Dictionary <Guid, string>();

            foreach (EntityState entity in AllEntities())
            {
                entity.JoinBattle(this);
            }

            StartBattle();
        }
Exemplo n.º 21
0
 internal void CreateCardToHand(AbstractCard abstractCard,
                                AbstractBattleUnit owner  = null,
                                QueueingType queueingType = QueueingType.TO_BACK)
 {
     Require.NotNull(abstractCard);
     abstractCard.Owner = owner;
     QueuedActions.ImmediateAction("CreateCardToHand", () =>
     {
         BattleRules.MarkCreatedCard(abstractCard, owner);
         ServiceLocator.GameState().Deck.Hand.Add(abstractCard);
         ServiceLocator.GetCardAnimationManager().AddHypercardsToHand(new List <Card> {
             abstractCard.CreateHyperCard()
         });
     }, queueingType);
 }
 public void AdvanceOrRetreatAsAppropriate()
 {
     if (BattleRules.CanAdvance(battleUnit))
     {
         ActionManager.Instance.PerformAdvanceActionIfPossible(battleUnit);
     }
     else if (BattleRules.CanFallBack(battleUnit))
     {
         ActionManager.Instance.PerformFallbackActionIfPossible(battleUnit);
     }
     else
     {
         ActionManager.Instance.Shout(battleUnit, "I can neither advance nor fall back!");
     }
 }
Exemplo n.º 23
0
    public void PlayCardFromHandIfAble_Action(AbstractBattleUnit target)
    {
        if (!CanPlay(target).Playable)
        {
            return;
        }
        var costPaid = BattleRules.ProcessPlayingCardCost(this);

        EvokeCardEffect(target, costPaid);
        BattleRules.RunOnPlayCardEffects(this, target, costPaid);
        if (state().Deck.Hand.Contains(this))
        {
            state().Deck.MoveCardToPile(this, CardPosition.DISCARD);
            ServiceLocator.GetCardAnimationManager().MoveCardToDiscardPile(this, assumedToExistInHand: true);
        }
        state().cardsPlayedThisTurn += 1;
    }
Exemplo n.º 24
0
 public void AttackUnitForDamage(AbstractBattleUnit targetUnit, AbstractBattleUnit sourceUnit, int baseDamageDealt, AbstractCard cardPlayed)
 {
     Require.NotNull(targetUnit);
     QueuedActions.DelayedActionWithCustomTrigger("AttackUnitForDamage_ShakeUnit", () => {
         if (targetUnit.IsDead || sourceUnit.IsDead)
         {
             // do nothing if it's already dead
             IsCurrentActionFinished = true;
             return;
         }
         targetUnit.CorrespondingPrefab.gameObject.AddComponent <ShakePrefab>();
         var shakePrefab = targetUnit.CorrespondingPrefab.gameObject.GetComponent <ShakePrefab>();
         shakePrefab.Begin(() => { IsCurrentActionFinished = true; });
         targetUnit.CorrespondingPrefab.FlickerFeedbacks.PlayFeedbacks();
         BattleRules.ProcessDamageWithCalculatedModifiers(sourceUnit, targetUnit, cardPlayed, baseDamageDealt);
     });
 }
    protected void SendMessageToFirstValidMouseButtonUpHandler(Vector2 position)
    {
        var elements = GetAllUIElements(position);

        if (elements == null)
        {
            return;
        }

        if (SelectCardInHandOverlay.INSTANCE.IsCardSelectBehaviorActive)
        {
            foreach (var element in elements)
            {
                var cardUiBehaviorNullable = element.GetComponent <CardUiBehaviors>();
                if (cardUiBehaviorNullable != null)
                {
                    var card = cardUiBehaviorNullable.GetComponent <Card>();
                    card.IsSelected = !card.IsSelected;
                    CardAnimationManager.INSTANCE.ReorientAllCards();
                    SelectCardInHandOverlay.INSTANCE.ExecuteClickingOnCard(cardUiBehaviorNullable);
                }
            }
            return;
        }

        foreach (var element in elements)
        {
            if (element.GetComponent <CardUiBehaviors>() != null)
            {
                // We're ignoring any case where we release the mouse button over a card
                return;
            }

            var battleUnitMousedOver = element.GetComponent <BattleUnitPrefab>();
            var battleUnitTargeted   = battleUnitMousedOver?.UnderlyingEntity;

            BattleRules.ProcessUiReleasingCardOverBattleUnit(logicalCard, battleUnitTargeted);

            if (element.GetComponent <CardPlayArea>() != null && logicalCard.TargetType == TargetType.NO_TARGET_OR_SELF)
            {
                ActionManager.Instance.AttemptPlayCardFromHand(this.logicalCard, null);
            }
        }

        ServiceLocator.GameState().UnselectCard();
    }
Exemplo n.º 26
0
    public void DamageUnitNonAttack(AbstractBattleUnit targetUnit, AbstractBattleUnit nullableSourceUnit, int baseDamageDealt)
    {
        if (targetUnit == null)
        {
            return;
        }
        QueuedActions.DelayedActionWithCustomTrigger("DamageUnitNonAttack_ShakeUnit", () => {
            if (targetUnit.IsDead)
            {
                // do nothing if it's already dead
                IsCurrentActionFinished = true;
                return;
            }
            targetUnit.CorrespondingPrefab.gameObject.AddComponent <ShakePrefab>();
            var shakePrefab = targetUnit.CorrespondingPrefab.gameObject.GetComponent <ShakePrefab>();
            shakePrefab.Begin(() => { IsCurrentActionFinished = true; });
            targetUnit.CorrespondingPrefab.FlickerFeedbacks.PlayFeedbacks();

            BattleRules.ProcessDamageWithCalculatedModifiers(nullableSourceUnit, targetUnit,
                                                             nullableCardPlayed: null,
                                                             baseDamage: baseDamageDealt,
                                                             isAttack: false);
        });
    }
Exemplo n.º 27
0
 public int DisplayedDamage(int?baseDamageOverride = null)
 {
     return(BattleRules.GetDisplayedDamageOnCard(this, baseDamageOverride));
 }
Exemplo n.º 28
0
 public int DisplayedDefense()
 {
     return(BattleRules.GetDisplayedDefenseOnCard(this));
 }
Exemplo n.º 29
0
 public int displayedDamage()
 {
     return(BattleRules.GetDisplayedDamageOnCard(this));
 }
Exemplo n.º 30
0
 // Called by the game to create an instance of this event.
 // Note: This constructor should not be available in the API.
 internal BattleCompletedEvent(BattleRules battleRules, BattleResults[] results)
     : base()
 {
     this.battleRules = battleRules;
     this.results = results;
 }
Exemplo n.º 31
0
 // Called by the game to create an instance of this event.
 // Note: This constructor should not be available in the API.
 internal BattleCompletedEvent(BattleRules battleRules, BattleResults[] results)
     : base()
 {
     this.battleRules = battleRules;
     this.results     = results;
 }
Exemplo n.º 32
0
            public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
            {
                string      robocodeVersion    = serializer.deserializeString(buffer);
                bool        isJuniorRobot      = serializer.deserializeBoolean(buffer);
                bool        isInteractiveRobot = serializer.deserializeBoolean(buffer);
                bool        isPaintRobot       = serializer.deserializeBoolean(buffer);
                bool        isAdvancedRobot    = serializer.deserializeBoolean(buffer);
                bool        isTeamRobot        = serializer.deserializeBoolean(buffer);
                bool        isTeamLeader       = serializer.deserializeBoolean(buffer);
                bool        isDroid            = serializer.deserializeBoolean(buffer);
                bool        isSentryRobot      = serializer.deserializeBoolean(buffer);
                string      name           = serializer.deserializeString(buffer);
                string      shortName      = serializer.deserializeString(buffer);
                string      veryShortName  = serializer.deserializeString(buffer);
                string      fullClassName  = serializer.deserializeString(buffer);
                string      shortClassName = serializer.deserializeString(buffer);
                BattleRules battleRules    = HiddenAccessN.createRules(
                    serializer.deserializeInt(buffer),     // BattlefieldWidth
                    serializer.deserializeInt(buffer),     // BattlefieldHeight
                    serializer.deserializeInt(buffer),     // NumRounds
                    serializer.deserializeDouble(buffer),  // GunCoolingRate
                    serializer.deserializeLong(buffer),    // InactivityTime
                    serializer.deserializeBoolean(buffer), // HideEnemyNames
                    serializer.deserializeInt(buffer)      // SentryBorderSize
                    );

                var    teammates = new List <string>();
                object item      = serializer.deserializeString(buffer);

                while (item != null)
                {
                    if (item is string)
                    {
                        teammates.Add((string)item);
                    }
                    item = serializer.deserializeString(buffer);
                }

                string teamName        = serializer.deserializeString(buffer);
                int    index           = serializer.deserializeInt(buffer);
                int    contestantIndex = serializer.deserializeInt(buffer);

                return(new RobotStatics(
                           robocodeVersion,
                           isJuniorRobot,
                           isInteractiveRobot,
                           isPaintRobot,
                           isAdvancedRobot,
                           isTeamRobot,
                           isTeamLeader,
                           isDroid,
                           isSentryRobot,
                           name,
                           shortName,
                           veryShortName,
                           fullClassName,
                           shortClassName,
                           battleRules,
                           teammates.ToArray(),
                           teamName,
                           index,
                           contestantIndex
                           ));
            }