public void Trigger(PartyMember partyMember, PartyBattleLayout partyBattleLayout)
        {
            int damage = partyMember.CalculateDamageTaken(this);
            if (damage > 0)
                partyMember.DoDamage(damage, true, false);
            if (partyMember.Alive)
                partyMember.ApplyStatusEffectsFromAttributes(setter, Attributes, battle);

            if (Attributes.Enhancement == Enhancement.Explosive)
            {
                ParticleEffect.AddExplosion(entity.GetCenter(), battle);
                List<PartyMember> partyMemberList = partyBattleLayout.GetListBehindTrap(this);
                if (partyMemberList != null && partyMemberList.Count > 0)
                {
                    PartyMember frontPartyMember = partyMemberList[0];
                    damage = frontPartyMember.CalculateDamageTaken(this);
                    frontPartyMember.DoDamage(damage, false);
                    if (frontPartyMember.Alive)
                        frontPartyMember.ApplyStatusEffectsFromAttributes(setter, Attributes, battle);
                }
            }
            else
                ParticleEffect.AddSmokePuff(entity.GetCenter(), battle);

            partyBattleLayout.RemoveTrap(this);
            Kill();
        }
        private bool partyMemberIsSelected(PartyMember partyMember)
        {
            BattleStates.SelectTarget selectTargetState = CurrentBattleState as BattleStates.SelectTarget;
            if (selectTargetState != null)
            {
                return(selectTargetState.PotentialTarget == partyMember);
            }

            return(false);
        }
Exemple #3
0
        private void _addMaxHealthStatModifier(object[] args)
        { // addMaxHealthStatModifier(string partyMemberSelector, int turns, int amount)
            string partyMemberSelector = (string)args[0];
            int    turns  = (int)args[1];
            int    amount = (int)args[2];

            PartyMember partyMember = getPartyMemberFromSelector(partyMemberSelector);

            partyMember.AddStatModifier(new StatModifier(turns, maxHealth: amount));
        }
        private void drawPartyMemberUi(PartyMember partyMember, Vector2 position, Vector2 headPadding, Vector2 barPadding, Vector2 barSize, Renderer renderer)
        {
            Vector2 screenScaleFactor = Game1.ScreenScaleFactor;
            Vector2 minScale          = new Vector2(MathHelper.Min(screenScaleFactor.X, screenScaleFactor.Y));
            Vector2 shadowOffset      = new Vector2(-5.0f, 5.0f) * minScale;
            Color   shadowColor       = Color.Black * 0.4f;

            TextureData textureData         = CharacterClassHeadTextureData[partyMember.CharacterClass];
            bool        partyMemberThinking = partyMemberIsThinking(partyMember);

            if (partyMemberThinking)
            {
                renderer.Draw(textureData, position + (shadowOffset * 2.0f), shadowColor, 0.0f, minScale, false);
            }
            renderer.Draw(textureData, position, Color.White, 0.0f, minScale, false);

            if (partyMemberIsSelected(partyMember))
            {
                renderer.Draw(arrowTextureData, position + new Vector2((textureData.Width / 2) - (arrowTextureData.Width / 2), -arrowTextureData.Height), Color.White, 0.0f, minScale, false);
            }

            position.X += (textureData.Width * screenScaleFactor.X) + headPadding.X;

            Vector2 partyMemberNameSize     = renderer.Font.MeasureString(partyMember.Name, Font.DefaultSize * minScale.Y);
            Vector2 partyMemberNamePosition = position + new Vector2(barSize.X / 2.0f, 20.0f * minScale.Y);

            if (partyMemberThinking)
            {
                renderer.DrawText(partyMember.Name, partyMemberNamePosition + shadowOffset, shadowColor, 0.0f, partyMemberNameSize / 2.0f, minScale);
            }
            renderer.DrawText(partyMember.Name, partyMemberNamePosition, Color.White, 0.0f, partyMemberNameSize / 2.0f, minScale);

            position.Y += partyMemberNameSize.Y + (20.0f * minScale.Y);
            float percentageHealth = partyMember.Health / (float)partyMember.MaxHealth;
            Color healthBarColor   = percentageHealth > 0.5f ? Color.Lerp(Color.Yellow, Color.Green, (percentageHealth - 0.5f) / 0.5f) : Color.Lerp(Color.Red, Color.Yellow, percentageHealth / 0.5f);

            if (partyMemberThinking)
            {
                drawBar(position + shadowOffset, barSize, 1.0f, shadowColor, false, renderer);
            }
            drawBar(position, barSize, percentageHealth, healthBarColor, true, renderer);
            string  barText     = "HP: " + partyMember.Health.ToString() + "/" + partyMember.MaxHealth;
            Vector2 barTextSize = renderer.Font.MeasureString(barText, Font.DefaultSize * minScale.Y);

            renderer.DrawText(barText, position + (barSize / 2.0f), Color.White, 0.0f, barTextSize / 2.0f, minScale);

            position.Y += barSize.Y * 1.5f;
            partyMember.ForEachStatusEffect((statusEffect) => {
                float widthWithPadding = barSize.Y * 1.1f;
                Vector2 scale          = new Vector2((1.0f / statusEffect.TextureData.Height) * barSize.Y);
                Vector2 nudge          = new Vector2((widthWithPadding - (statusEffect.TextureData.Width * scale.X)) / 2.0f, 0.0f);
                renderer.Draw(statusEffect.TextureData, position + (statusEffect.TextureData.Origin * scale) + nudge, Color.White, 0.0f, scale, false);
                position.X += barSize.Y * 1.1f;
            });
        }
Exemple #5
0
        public Trap GetTrapInFrontOfPartyMember(PartyMember partyMember)
        {
            List <PartyMember> list = GetListWithPartyMember(partyMember);
            int index = layout.IndexOf(list);

            if (index < 0 || index >= traps.Length)
            {
                return(null);
            }
            return(traps[index]);
        }
Exemple #6
0
        private List <PartyMember> newListWithPartyMember(PartyMember partyMember)
        {
            if (partyMember == null)
            {
                throw new Exception("PartyMember cannot be null");
            }
            List <PartyMember> result = new List <PartyMember>(1);

            result.Add(partyMember);
            return(result);
        }
Exemple #7
0
 public List <PartyMember> GetListWithPartyMember(PartyMember partyMember)
 {
     foreach (List <PartyMember> list in layout)
     {
         if (list.Contains(partyMember))
         {
             return(list);
         }
     }
     throw new Exception("PartyMember not found in PartyBattleLayout");
 }
Exemple #8
0
 public ScriptRunner(Script script, Battle battle, PartyMember actor, PartyMember target, ScriptRunnerMode mode = ScriptRunnerMode.Normal)
 {
     this.script       = script;
     scriptActionIndex = 0;
     this.battle       = battle;
     this.actor        = actor;
     this.target       = target;
     time = 0.0f;
     nestedScriptRunners = new List <NestedScriptRunner>();
     this.mode           = mode;
     blocked             = false;
 }
 public PartyBattleLayout GetPartyBattleLayoutForPartyMember(PartyMember partyMember)
 {
     if (PlayerParty.Contains(partyMember))
     {
         return(PlayerPartyLayout);
     }
     if (EnemyParty.Contains(partyMember))
     {
         return(EnemyPartyLayout);
     }
     return(null);
 }
 public Party GetPartyForPartyMember(PartyMember partyMember)
 {
     if (PlayerParty.Contains(partyMember))
     {
         return(PlayerParty);
     }
     if (EnemyParty.Contains(partyMember))
     {
         return(EnemyParty);
     }
     return(null);
 }
 public ScriptRunner(Script script, Battle battle, PartyMember actor, PartyMember target, ScriptRunnerMode mode = ScriptRunnerMode.Normal)
 {
     this.script = script;
     scriptActionIndex = 0;
     this.battle = battle;
     this.actor = actor;
     this.target = target;
     time = 0.0f;
     nestedScriptRunners = new List<NestedScriptRunner>();
     this.mode = mode;
     blocked = false;
 }
 protected Inventory getInventoryFromThinkActionType(ThinkActionType thinkActionType, PartyMember partyMember)
 {
     Party party = Battle.GetPartyForPartyMember(partyMember);
     if (party == null)
         return null;
     switch (thinkActionType)
     {
     case ThinkActionType.Attack: return party.WeaponInventories[partyMember.CharacterClass];
     case ThinkActionType.Defend: return party.ShieldInventory;
     case ThinkActionType.UseItem: return party.ItemInventory;
     default: return null;
     }
 }
Exemple #13
0
        public void PlaceTrapInFrontOfPartyMember(PartyMember partyMember, Trap trap)
        {
            int index = layout.IndexOf(GetListWithPartyMember(partyMember));

            if (index < 0 || index >= traps.Length)
            {
                return;
            }
            if (traps[index] != null)
            {
                traps[index].Kill();
            }
            traps[index] = trap;
        }
Exemple #14
0
 public bool FearsPartyMember(PartyMember other)
 {
     foreach (StatusEffect statusEffect in StatusEffects)
     {
         if (statusEffect.Type == StatusEffectType.Fear)
         {
             if ((statusEffect as StatusEffects.Fear).Inflictor == other)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #15
0
        private List <PartyMember> getTargetsFromEnhancement(PartyMember target, Enhancement enhancement)
        {
            PartyBattleLayout  layout = battle.GetPartyBattleLayoutForPartyMember(target);
            List <PartyMember> result;

            switch (enhancement)
            {
            case Enhancement.Piercing:
                List <PartyMember> list = layout.GetListWithPartyMember(target);
                result = new List <PartyMember>(2);
                result.Add(list[0]);
                if (list.Count > 1)
                {
                    result.Add(list[1]);
                }
                break;

            case Enhancement.Relentless:
                result = new List <PartyMember>(layout.GetListWithPartyMember(target)); // new list isn't created in PartyBattleLayout#PartyMembersList
                break;

            case Enhancement.Explosive:
                result = layout.PartyMembersArea(target);
                break;

            case Enhancement.Inaccurate:
                const double chanceOfMiss = 0.4;
                result = new List <PartyMember>(1);
                if (Game1.Random.NextDouble() <= chanceOfMiss)
                {
                    List <PartyMember> targetList = layout.GetListWithPartyMember(target);
                    List <PartyMember> otherList  = layout.RelativeList(targetList, Game1.Random.Next(1) == 0 ? 1 : -1);
                    if (otherList != null && otherList.Count > 0)
                    {
                        result.Add(otherList[0]);
                    }
                }
                else
                {
                    result.Add(target);
                }
                break;

            default:
                result = new List <PartyMember>(1);
                result.Add(target);
                break;
            }
            return(result);
        }
Exemple #16
0
        private void _moveToIdlePosition(object[] args)
        { // moveToIdlePosition(string partyMemberSelector, bool decelerate, Script callback)
            string partyMemberSelector = (string)args[0];
            float  speed      = (float)args[1];
            bool   decelerate = (bool)args[2];
            Script callback   = (Script)args[3];

            PartyMember partyMember     = getPartyMemberFromSelector(partyMemberSelector);
            Entity      entity          = partyMember.BattleEntity;
            Vector2     directionVector = partyMember.BattleEntityIdlePosition - entity.Position;
            bool        movingRight     = directionVector.X > 0.0f;
            float       distance        = directionVector.Length();

            directionVector.Normalize();
            entity.Velocity = directionVector * speed;
            float   time             = distance / speed;
            Vector2 originalVelocity = entity.Velocity;

            this.blocked = true;
            bool         unblocked = false;
            const float  velocityToleranceForUnblocking = 50.0f;
            const float  velocityToleranceForStopping   = 1.0f;
            ScriptRunner self = this;

            entity.UpdateExtensions.Add(new UpdateExtension((updateExtension, delta) => {
                if (decelerate)
                {
                    float currentDistance = (partyMember.BattleEntityIdlePosition - entity.Position).Length();
                    entity.Velocity       = originalVelocity * (currentDistance / distance);
                }
                else
                {
                    time -= delta.Time;
                }

                if (!unblocked && (time <= 0.0f || (movingRight && entity.Velocity.X < velocityToleranceForUnblocking) || (!movingRight && entity.Velocity.X > -velocityToleranceForUnblocking)))
                {
                    self.blocked = false;
                    unblocked    = true;
                    addNestedScriptRunner(callback, 0.0f);
                }

                if (unblocked && (time <= 0.0f || (movingRight && entity.Velocity.X < velocityToleranceForStopping) || (!movingRight && entity.Velocity.X > -velocityToleranceForStopping)))
                {
                    entity.Position        = partyMember.BattleEntityIdlePosition;
                    updateExtension.Active = false;
                }
            }));
        }
Exemple #17
0
        private void _createTrap(object[] args)
        { // createTrap(string actorPartyMemberSelector, string targetPartyMemberSelector, string spriteName)
            string actorPartyMemberSelector  = (string)args[0];
            string targetPartyMemberSelector = (string)args[1];
            string spriteName = (string)args[2];

            PartyMember actorPartyMember = getPartyMemberFromSelector(actorPartyMemberSelector);
            PartyMember frontPartyMember = getPartyMemberFromSelector(targetPartyMemberSelector + ">list>front");
            float       nudgeMultiplierX = battle.GetPartyForPartyMember(actorPartyMember) == battle.PlayerParty ? 1.0f : -1.0f;
            Rectangle   boundingBox      = frontPartyMember.BattleEntity.GetBoundingBox();
            Vector2     position         = new Vector2(boundingBox.X + (boundingBox.Width / 2.0f) + (boundingBox.Width * nudgeMultiplierX), boundingBox.Bottom);

            Trap trap = new Trap(ResourceManager.GetNewSprite(spriteName), position, actorPartyMember.EquippedWeapon.Attributes, actorPartyMember.EquippedWeapon.Data, actorPartyMember, battle);

            battle.GetPartyBattleLayoutForPartyMember(frontPartyMember).PlaceTrapInFrontOfPartyMember(frontPartyMember, trap);
        }
Exemple #18
0
        private void _createParticleEffectOnPartyMember(object[] args)
        { // createParticleEffectOnPartyMember(string partyMemberSelector, int particleCount, string textureDataName, float speed, float gravity, float maxScale, float lifeTime, bool rotate)
            string partyMemberSelector = (string)args[0];
            int    particleCount       = (int)args[1];
            string textureDataName     = (string)args[2];
            float  speed    = (float)args[3];
            float  gravity  = (float)args[4];
            float  maxScale = (float)args[5];
            float  lifeTime = (float)args[6];
            bool   rotate   = (bool)args[7];

            PartyMember partyMember = getPartyMemberFromSelector(partyMemberSelector);
            TextureData textureData = ResourceManager.GetTextureData(textureDataName);

            Scene.AddEntity(new ParticleEffect(partyMember.BattleEntity.GetCenter(), Color.White, particleCount, textureData, speed, gravity, maxScale, lifeTime, rotate));
        }
        public Trap(Sprite sprite, Vector2 position, Attributes attributes, WeaponData weaponData, PartyMember setter, Battle battle)
            : base(attributes)
        {
            if (attributes == null)
                throw new Exception("Attributes cannot be null");
            if (setter == null)
                throw new Exception("PartyMember setter cannot be null");
            if (battle == null)
                throw new Exception("Battle cannot be null");

            this.setter = setter;
            this.battle = battle;
            Data = weaponData;
            entity = new Entity(sprite, position);
            entity.RenderShadow = true;
            entity.UpdateExtensions.Add(new UpdateExtension((updateExtension, delta) => Update(delta)));
            Scene.AddEntity(entity);
        }
Exemple #20
0
        private void _moveTo(object[] args)
        { // moveTo(string actorPartyMemberSelector, string targetPartyMemberSelector, float speed, bool accelerate, Script callback)
            string actorPartyMemberSelector  = (string)args[0];
            string targetPartyMemberSelector = (string)args[1];
            float  speed      = (float)args[2];
            bool   accelerate = (bool)args[3];
            Script callback   = (Script)args[4];

            PartyMember actor          = getPartyMemberFromSelector(actorPartyMemberSelector);
            PartyMember target         = getPartyMemberFromSelector(targetPartyMemberSelector);
            Entity      actorEntity    = actor.BattleEntity;
            Entity      targetEntity   = target.BattleEntity;
            Vector2     velocityVector = targetEntity.Position - actorEntity.Position;

            velocityVector.Normalize();
            velocityVector *= speed;
            if (accelerate)
            {
                actorEntity.Acceleration = velocityVector;
            }
            else
            {
                actorEntity.Velocity = velocityVector;
            }

            this.blocked = true;
            ScriptRunner self = this;

            actorEntity.UpdateExtensions.Add(new UpdateExtension((updateExtension, delta) => {
                if (actorEntity.CollidesWith(targetEntity))
                {
                    updateExtension.Active = false;
                    self.blocked           = false;
                    TriggerTrap(actor, target);
                    if (actor.Alive)
                    {
                        addNestedScriptRunner(callback, 0.0f);
                    }
                }
            }));
        }
        public Projectile(Sprite sprite, Vector2 position, bool facingRight, PartyMember actor, PartyMember target, float speed, Action<Projectile> collisionCallback)
            : base(sprite, position)
        {
            if (actor == null)
                throw new Exception("PartyMember actor cannot be null");
            if (target == null)
                throw new Exception("PartyMember target cannot be null");
            if (collisionCallback == null)
                throw new Exception("Action<Projectile> collisionCallback cannot be null");
            this.actor = actor;
            this.target = target;
            this.collisionCallback = collisionCallback;

            Vector2 directionVector = target.BattleEntity.GetCenter() - GetCenter();
            distance = directionVector.Length();
            directionVector.Normalize();
            Velocity = speed * directionVector;
            Rotation = (facingRight ? 0.0f : MathHelper.Pi) + (float)Math.Atan2(directionVector.Y, directionVector.X);

            collided = false;
        }
        private bool partyMemberIsThinking(PartyMember partyMember)
        {
            BattleStates.Think thinkState = CurrentBattleState as BattleStates.Think;
            if (thinkState != null)
            {
                return(thinkState.CurrentPartyMember == partyMember);
            }

            BattleStates.SelectTarget selectTargetState = CurrentBattleState as BattleStates.SelectTarget;
            if (selectTargetState != null)
            {
                return(selectTargetState.Actor == partyMember);
            }

            BattleStates.MoveActor moveActorState = CurrentBattleState as BattleStates.MoveActor;
            if (moveActorState != null)
            {
                return(moveActorState.Actor == partyMember);
            }

            return(false);
        }
Exemple #23
0
        private void _playAnimation(object[] args)
        { // playAnimation(string partyMemberSelector, string animationName, [Script onFinishCallback])
            string partyMemberSelector = (string)args[0];
            string animationName       = (string)args[1];
            Script onFinishCallback    = args.Length <= 2 ? null : (Script)args[2];

            PartyMember    partyMember    = getPartyMemberFromSelector(partyMemberSelector);
            AnimationState animationState = partyMember.BattleEntity.AnimationState;
            Animation      animation      = animationState.Data.SkeletonData.FindAnimation(animationName);

            if (animation == null)
            {
                throw new Exception("Animation '" + animationName + "' could not be found");
            }

            animationState.SetAnimation(animation, false);
            animationState.AddAnimation(partyMember.GetBattleEntityIdleAnimationName(), true);

            if (onFinishCallback != null)
            {
                addNestedScriptRunner(onFinishCallback, animation.Duration);
            }
        }
Exemple #24
0
        public void ArrangeRandomly()
        {
            foreach (List <PartyMember> list in layout)
            {
                list.Clear();
            }
            List <PartyMember> partyMembersLeftToAdd = new List <PartyMember>(party);

            while (partyMembersLeftToAdd.Count > 0)
            {
                List <PartyMember> list        = layout.Sample();
                PartyMember        partyMember = partyMembersLeftToAdd.Sample();
                list.Add(partyMember);
                partyMembersLeftToAdd.Remove(partyMember);
            }

            List <List <PartyMember> > newLayout = new List <List <PartyMember> >(layout.Where(list => list.Count > 0));

            while (newLayout.Count < layout.Count)
            {
                newLayout.Add(new List <PartyMember>());
            }
            layout = newLayout;
        }
        public Trap(Sprite sprite, Vector2 position, Attributes attributes, WeaponData weaponData, PartyMember setter, Battle battle)
            : base(attributes)
        {
            if (attributes == null)
            {
                throw new Exception("Attributes cannot be null");
            }
            if (setter == null)
            {
                throw new Exception("PartyMember setter cannot be null");
            }
            if (battle == null)
            {
                throw new Exception("Battle cannot be null");
            }

            this.setter         = setter;
            this.battle         = battle;
            Data                = weaponData;
            entity              = new Entity(sprite, position);
            entity.RenderShadow = true;
            entity.UpdateExtensions.Add(new UpdateExtension((updateExtension, delta) => Update(delta)));
            Scene.AddEntity(entity);
        }
        public void Trigger(PartyMember partyMember, PartyBattleLayout partyBattleLayout)
        {
            int damage = partyMember.CalculateDamageTaken(this);

            if (damage > 0)
            {
                partyMember.DoDamage(damage, true, false);
            }
            if (partyMember.Alive)
            {
                partyMember.ApplyStatusEffectsFromAttributes(setter, Attributes, battle);
            }

            if (Attributes.Enhancement == Enhancement.Explosive)
            {
                ParticleEffect.AddExplosion(entity.GetCenter(), battle);
                List <PartyMember> partyMemberList = partyBattleLayout.GetListBehindTrap(this);
                if (partyMemberList != null && partyMemberList.Count > 0)
                {
                    PartyMember frontPartyMember = partyMemberList[0];
                    damage = frontPartyMember.CalculateDamageTaken(this);
                    frontPartyMember.DoDamage(damage, false);
                    if (frontPartyMember.Alive)
                    {
                        frontPartyMember.ApplyStatusEffectsFromAttributes(setter, Attributes, battle);
                    }
                }
            }
            else
            {
                ParticleEffect.AddSmokePuff(entity.GetCenter(), battle);
            }

            partyBattleLayout.RemoveTrap(this);
            Kill();
        }
        private void drawPartyMemberUi(PartyMember partyMember, Vector2 position, Vector2 headPadding, Vector2 barPadding, Vector2 barSize, Renderer renderer)
        {
            Vector2 screenScaleFactor = Game1.ScreenScaleFactor;
            Vector2 minScale = new Vector2(MathHelper.Min(screenScaleFactor.X, screenScaleFactor.Y));
            Vector2 shadowOffset = new Vector2(-5.0f, 5.0f) * minScale;
            Color shadowColor = Color.Black * 0.4f;

            TextureData textureData = CharacterClassHeadTextureData[partyMember.CharacterClass];
            bool partyMemberThinking = partyMemberIsThinking(partyMember);

            if (partyMemberThinking)
            {
                renderer.Draw(textureData, position + (shadowOffset * 2.0f), shadowColor, 0.0f, minScale, false);
            }
            renderer.Draw(textureData, position, Color.White, 0.0f, minScale, false);

            if (partyMemberIsSelected(partyMember))
                renderer.Draw(arrowTextureData, position + new Vector2((textureData.Width / 2) - (arrowTextureData.Width / 2), -arrowTextureData.Height), Color.White, 0.0f, minScale, false);

            position.X += (textureData.Width * screenScaleFactor.X) + headPadding.X;

            Vector2 partyMemberNameSize = renderer.Font.MeasureString(partyMember.Name, Font.DefaultSize * minScale.Y);
            Vector2 partyMemberNamePosition = position + new Vector2(barSize.X / 2.0f, 20.0f * minScale.Y);
            if (partyMemberThinking)
                renderer.DrawText(partyMember.Name, partyMemberNamePosition + shadowOffset, shadowColor, 0.0f, partyMemberNameSize / 2.0f, minScale);
            renderer.DrawText(partyMember.Name, partyMemberNamePosition, Color.White, 0.0f, partyMemberNameSize / 2.0f, minScale);

            position.Y += partyMemberNameSize.Y + (20.0f * minScale.Y);
            float percentageHealth = partyMember.Health / (float)partyMember.MaxHealth;
            Color healthBarColor = percentageHealth > 0.5f ? Color.Lerp(Color.Yellow, Color.Green, (percentageHealth - 0.5f) / 0.5f) : Color.Lerp(Color.Red, Color.Yellow, percentageHealth / 0.5f);
            if (partyMemberThinking)
                drawBar(position + shadowOffset, barSize, 1.0f, shadowColor, false, renderer);
            drawBar(position, barSize, percentageHealth, healthBarColor, true, renderer);
            string barText = "HP: " + partyMember.Health.ToString() + "/" + partyMember.MaxHealth;
            Vector2 barTextSize = renderer.Font.MeasureString(barText, Font.DefaultSize * minScale.Y);
            renderer.DrawText(barText, position + (barSize / 2.0f), Color.White, 0.0f, barTextSize / 2.0f, minScale);

            position.Y += barSize.Y * 1.5f;
            partyMember.ForEachStatusEffect((statusEffect) => {
                float widthWithPadding = barSize.Y * 1.1f;
                Vector2 scale = new Vector2((1.0f / statusEffect.TextureData.Height) * barSize.Y);
                Vector2 nudge = new Vector2((widthWithPadding - (statusEffect.TextureData.Width * scale.X)) / 2.0f, 0.0f);
                renderer.Draw(statusEffect.TextureData, position + (statusEffect.TextureData.Origin * scale) + nudge, Color.White, 0.0f, scale, false);
                position.X += barSize.Y * 1.1f;
            });
        }
        private bool partyMemberIsSelected(PartyMember partyMember)
        {
            BattleStates.SelectTarget selectTargetState = CurrentBattleState as BattleStates.SelectTarget;
            if (selectTargetState != null)
                return selectTargetState.PotentialTarget == partyMember;

            return false;
        }
 public void RemovePartyMember(PartyMember partyMember)
 {
     foreach (List<PartyMember> list in layout)
     {
         if (list.Remove(partyMember))
             break;
     }
 }
 public bool FearsPartyMember(PartyMember other)
 {
     foreach (StatusEffect statusEffect in StatusEffects)
     {
         if (statusEffect.Type == StatusEffectType.Fear)
         {
             if ((statusEffect as StatusEffects.Fear).Inflictor == other)
                 return true;
         }
     }
     return false;
 }
 public virtual void EndTurnStart(PartyMember partyMember)
 {
 }
        public List<PartyMember> PartyMembersArea(PartyMember partyMember)
        {
            List<PartyMember> result = new List<PartyMember>(5);
            result.Add(partyMember);

            List<PartyMember> partyMemberList = GetListWithPartyMember(partyMember);
            int partyMemberIndex = partyMemberList.IndexOf(partyMember);
            if (partyMemberIndex > 0)
                result.Add(partyMemberList[partyMemberIndex - 1]);
            if (partyMemberIndex + 1 < partyMemberList.Count)
                result.Add(partyMemberList[partyMemberIndex + 1]);

            List<PartyMember> adjacentPartyMemberList = RelativeList(partyMemberList, 1);
            if (adjacentPartyMemberList != null && partyMemberIndex < adjacentPartyMemberList.Count)
                result.Add(adjacentPartyMemberList[partyMemberIndex]);
            adjacentPartyMemberList = RelativeList(partyMemberList, -1);
            if (adjacentPartyMemberList != null && partyMemberIndex < adjacentPartyMemberList.Count)
                result.Add(adjacentPartyMemberList[partyMemberIndex]);

            return result;
        }
Exemple #33
0
        public Projectile(Sprite sprite, Vector2 position, bool facingRight, PartyMember actor, PartyMember target, float speed, Action <Projectile> collisionCallback)
            : base(sprite, position)
        {
            if (actor == null)
            {
                throw new Exception("PartyMember actor cannot be null");
            }
            if (target == null)
            {
                throw new Exception("PartyMember target cannot be null");
            }
            if (collisionCallback == null)
            {
                throw new Exception("Action<Projectile> collisionCallback cannot be null");
            }
            this.actor             = actor;
            this.target            = target;
            this.collisionCallback = collisionCallback;

            Vector2 directionVector = target.BattleEntity.GetCenter() - GetCenter();

            distance = directionVector.Length();
            directionVector.Normalize();
            Velocity = speed * directionVector;
            Rotation = (facingRight ? 0.0f : MathHelper.Pi) + (float)Math.Atan2(directionVector.Y, directionVector.X);

            collided = false;
        }
 public List<PartyMember> GetListWithPartyMember(PartyMember partyMember)
 {
     foreach (List<PartyMember> list in layout)
     {
         if (list.Contains(partyMember))
             return list;
     }
     throw new Exception("PartyMember not found in PartyBattleLayout");
 }
 private void TriggerTrap(PartyMember actor, PartyMember target)
 {
     PartyBattleLayout battleLayout = battle.GetPartyBattleLayoutForPartyMember(target);
     Trap trap = battleLayout.GetTrapInFrontOfPartyMember(target);
     if (trap != null)
         trap.Trigger(actor, battleLayout);
 }
Exemple #36
0
 public virtual void EndTurnStart(PartyMember partyMember)
 {
 }
Exemple #37
0
 public virtual void EndTurnUpdate(PartyMember partyMember, Delta delta)
 {
 }
        private void movePartyMemberWithinList(PartyMember partyMember, bool edgeIndexIsZero, int nextRelativeIndex, BattleStates.Think thinkState)
        {
            if (!party.Contains(partyMember))
                return;

            List<PartyMember> list = GetListWithPartyMember(partyMember);
            int partyMemberIndex = list.IndexOf(partyMember);
            if (partyMemberIndex != (edgeIndexIsZero ? 0 : list.Count - 1)) // if not at the end already
            {
                list.RemoveAt(partyMemberIndex);
                int index = partyMemberIndex + nextRelativeIndex;
                if (index == 0 && list.Count > 0 && thinkState.PartyMemberHasCompletedThinkAction(list[index]))
                {
                    Weapon frontPartyMemberWeapon = list[index].EquippedWeapon;
                    if (frontPartyMemberWeapon != null && frontPartyMemberWeapon.Data.WeaponType == WeaponType.Melee)
                        ++index;
                }
                list.Insert(index, partyMember);
            }
        }
 public int CalculateDamageTaken(PartyMember enemy)
 {
     return calculateDamageTaken(enemy.calculateFinalAttackStat());
 }
        private bool partyMemberIsThinking(PartyMember partyMember)
        {
            BattleStates.Think thinkState = CurrentBattleState as BattleStates.Think;
            if (thinkState != null)
                return thinkState.CurrentPartyMember == partyMember;

            BattleStates.SelectTarget selectTargetState = CurrentBattleState as BattleStates.SelectTarget;
            if (selectTargetState != null)
                return selectTargetState.Actor == partyMember;

            BattleStates.MoveActor moveActorState = CurrentBattleState as BattleStates.MoveActor;
            if (moveActorState != null)
                return moveActorState.Actor == partyMember;

            return false;
        }
 // last item/back is towards edge of screen
 public void MovePartyMemberBack(PartyMember partyMember, BattleStates.Think thinkState)
 {
     if (!partyMember.HasStatusEffectOfType(StatusEffectType.Paralysis))
         movePartyMemberWithinList(partyMember, false, 1, thinkState);
 }
        protected Inventory getInventoryFromThinkActionType(ThinkActionType thinkActionType, PartyMember partyMember)
        {
            Party party = Battle.GetPartyForPartyMember(partyMember);

            if (party == null)
            {
                return(null);
            }
            switch (thinkActionType)
            {
            case ThinkActionType.Attack: return(party.WeaponInventories[partyMember.CharacterClass]);

            case ThinkActionType.Defend: return(party.ShieldInventory);

            case ThinkActionType.UseItem: return(party.ItemInventory);

            default: return(null);
            }
        }
 public void MovePartyMemberUp(PartyMember partyMember, BattleStates.Think thinkState)
 {
     if (!partyMember.HasStatusEffectOfType(StatusEffectType.Paralysis))
         movePartyMemberAcrossLists(partyMember, true, -1, thinkState);
 }
 public Trap GetTrapInFrontOfPartyMember(PartyMember partyMember)
 {
     List<PartyMember> list = GetListWithPartyMember(partyMember);
     int index = layout.IndexOf(list);
     if (index < 0 || index >= traps.Length)
         return null;
     return traps[index];
 }
Exemple #45
0
        private void _doDamage(object[] args)
        { // doDamage(string actorPartyMemberSelector, string targetPartyMemberSelector)
            string actorPartyMemberSelector  = (string)args[0];
            string targetPartyMemberSelector = (string)args[1];

            PartyMember actor          = getPartyMemberFromSelector(actorPartyMemberSelector);
            PartyMember selectedTarget = getPartyMemberFromSelector(targetPartyMemberSelector);

            List <PartyMember> targets;

            if (actor.EquippedWeapon == null)
            {
                targets = new List <PartyMember>(1);
                targets.Add(selectedTarget);
            }
            else
            {
                targets = getTargetsFromEnhancement(selectedTarget, actor.EquippedWeapon.Attributes.Enhancement);
                if (actor.EquippedWeapon.Attributes.Enhancement == Enhancement.Explosive)
                {
                    ParticleEffect.AddExplosion(selectedTarget.BattleEntity.GetCenter(), battle);
                }
            }

            int damage = -1;

            foreach (PartyMember target in targets)
            {
                bool breakNow = false;
                if (actor.EquippedWeapon.Attributes.Enhancement == Enhancement.Relentless)
                {
                    if (damage < 0)
                    {
                        damage = target.CalculateDamageTaken(actor);
                    }
                    int damageDealt = Math.Min(damage, target.Health);
                    target.DoDamage(damage, false);
                    damage -= damageDealt;
                    if (damage <= 0)
                    {
                        breakNow = true;
                    }
                }
                else
                {
                    damage = target.CalculateDamageTaken(actor);
                    target.DoDamage(damage, false);
                }

                if (actor.EquippedWeapon != null && target.Alive)
                {
                    target.ApplyStatusEffectsFromAttributes(actor, actor.EquippedWeapon.Attributes, battle);
                }

                if (target.EquippedShield != null)
                {
                    if (actor.EquippedWeapon.Data.WeaponType == WeaponType.Melee)
                    {
                        if (target.EquippedShield.Attributes.Enhancement == Enhancement.Spiky)
                        {
                            actor.DoDamage(Math.Max(damage / 10, 1), true, false);
                        }
                        actor.ApplyStatusEffectsFromAttributes(target, target.EquippedShield.Attributes, battle);
                    }

                    if (target.EquippedShield.Data.Script != null)
                    {
                        addNestedScriptRunner(target.EquippedShield.Data.Script, 0.0f);
                    }
                }

                if (breakNow)
                {
                    break;
                }
            }

            if (actor.EquippedWeapon != null && actor.EquippedWeapon.Attributes.Handling == Handling.Uncomfortable)
            {
                actor.DoDamage(Math.Max(actor.CalculateDamageTaken(actor) / 10, 1), true);
            }
        }
 // first item/forward is towards middle of screen
 public void MovePartyMemberForward(PartyMember partyMember, BattleStates.Think thinkState)
 {
     if (!partyMember.HasStatusEffectOfType(StatusEffectType.Paralysis))
         movePartyMemberWithinList(partyMember, true, -1, thinkState);
 }
 public void DrawArrowOverPartyMember(PartyMember partyMember, Color color, Renderer renderer)
 {
     Rectangle boundingBox = partyMember.BattleEntity.GetBoundingBox();
     Vector2 position = new Vector2(boundingBox.X + (boundingBox.Width / 2) - (arrowTextureData.Width / 2), boundingBox.Y - arrowTextureData.Height);
     renderer.Draw(arrowTextureData, position, color);
 }
 public bool PartyMemberInFrontLine(PartyMember partyMember)
 {
     if (party.Contains(partyMember))
         return GetListWithPartyMember(partyMember).IndexOf(partyMember) == 0;
     return false;
 }
 public PartyBattleLayout GetPartyBattleLayoutForPartyMember(PartyMember partyMember)
 {
     if (PlayerParty.Contains(partyMember))
         return PlayerPartyLayout;
     if (EnemyParty.Contains(partyMember))
         return EnemyPartyLayout;
     return null;
 }
 public void PlaceTrapInFrontOfPartyMember(PartyMember partyMember, Trap trap)
 {
     int index = layout.IndexOf(GetListWithPartyMember(partyMember));
     if (index < 0 || index >= traps.Length)
         return;
     if (traps[index] != null)
         traps[index].Kill();
     traps[index] = trap;
 }
 public Party GetPartyForPartyMember(PartyMember partyMember)
 {
     if (PlayerParty.Contains(partyMember))
         return PlayerParty;
     if (EnemyParty.Contains(partyMember))
         return EnemyParty;
     return null;
 }
        private void movePartyMemberAcrossLists(PartyMember partyMember, bool edgeListIndexIsZero, int nextListRelativeIndex, BattleStates.Think thinkState)
        {
            if (!party.Contains(partyMember))
                return;

            List<PartyMember> list = GetListWithPartyMember(partyMember);
            int listIndex = layout.IndexOf(list);
            if (listIndex == (edgeListIndexIsZero ? 0 : layout.Count - 1)) // if the edge list
                return;

            List<PartyMember> nextList = layout[listIndex + nextListRelativeIndex];
            int partyMemberPosition = Math.Min(list.IndexOf(partyMember), nextList.Count);
            list.Remove(partyMember);
            if (partyMemberPosition == 0 && nextList.Count > 0 && thinkState.PartyMemberHasCompletedThinkAction(nextList[partyMemberPosition]))
            {
                Weapon frontPartyMemberWeapon = nextList[partyMemberPosition].EquippedWeapon;
                if (frontPartyMemberWeapon != null && frontPartyMemberWeapon.Data.WeaponType == WeaponType.Melee)
                    ++partyMemberPosition;
            }
            nextList.Insert(partyMemberPosition, partyMember);
        }
Exemple #53
0
 public int CalculateDamageTaken(PartyMember enemy)
 {
     return(calculateDamageTaken(enemy.calculateFinalAttackStat()));
 }
 private List<PartyMember> newListWithPartyMember(PartyMember partyMember)
 {
     if (partyMember == null)
         throw new Exception("PartyMember cannot be null");
     List<PartyMember> result = new List<PartyMember>(1);
     result.Add(partyMember);
     return result;
 }
 private List<PartyMember> getTargetsFromEnhancement(PartyMember target, Enhancement enhancement)
 {
     PartyBattleLayout layout = battle.GetPartyBattleLayoutForPartyMember(target);
     List<PartyMember> result;
     switch (enhancement)
     {
     case Enhancement.Piercing:
         List<PartyMember> list = layout.GetListWithPartyMember(target);
         result = new List<PartyMember>(2);
         result.Add(list[0]);
         if (list.Count > 1)
             result.Add(list[1]);
         break;
     case Enhancement.Relentless:
         result = new List<PartyMember>(layout.GetListWithPartyMember(target)); // new list isn't created in PartyBattleLayout#PartyMembersList
         break;
     case Enhancement.Explosive:
         result = layout.PartyMembersArea(target);
         break;
     case Enhancement.Inaccurate:
         const double chanceOfMiss = 0.4;
         result = new List<PartyMember>(1);
         if (Game1.Random.NextDouble() <= chanceOfMiss)
         {
             List<PartyMember> targetList = layout.GetListWithPartyMember(target);
             List<PartyMember> otherList = layout.RelativeList(targetList, Game1.Random.Next(1) == 0 ? 1 : -1);
             if (otherList != null && otherList.Count > 0)
                 result.Add(otherList[0]);
         }
         else
             result.Add(target);
         break;
     default:
         result = new List<PartyMember>(1);
         result.Add(target);
         break;
     }
     return result;
 }
 public virtual void EndTurnUpdate(PartyMember partyMember, Delta delta)
 {
 }
        public void ApplyStatusEffectsFromAttributes(PartyMember inflictor, Attributes attributes, Battle battle)
        {
            bool sameParty = battle.GetPartyForPartyMember(inflictor) == battle.GetPartyForPartyMember(this);

            StatusEffect statusEffect;
            switch (attributes.Status)
            {
            case Status.Poisonous: statusEffect = new StatusEffects.Poison(); break;
            case Status.Shocking: statusEffect = new StatusEffects.Paralysis(); break;
            case Status.Scary: statusEffect = sameParty || !inflictor.Alive ? null : new StatusEffects.Fear(inflictor); break;
            default: statusEffect = null; break;
            }
            if (statusEffect != null)
                AddStatusEffect(statusEffect);

            if (attributes.Affiliation == Affiliation.Doom && !sameParty && inflictor.Alive)
                AddStatusEffect(new StatusEffects.Doom(inflictor));
        }