Exemplo n.º 1
0
        public static void attemptSkillAward(Entity receiver, Entity awarder, float rSkill, float aSkill, SkillName skillname, int amount)
        {
            Interactable interactor = ComponentMapper.get <Interactable> (receiver);
            Interactable interactee = ComponentMapper.get <Interactable> (awarder);

            //only do if interaction supported
            if (interactor != null && interactor != null)
            {
                //only skill-up if you can
                if (interactor.SupportedInteractions.MAY_ADVANCE &&
                    interactee.SupportedInteractions.CAUSES_ADVANCEMENT)
                {
                    //if still possible to skill-up
                    if (rSkill < aSkill)
                    {
                        if (rand.NextDouble() <= ((double)(aSkill - rSkill) / (double)aSkill) * 0.5)
                        {
                            UtilFactory.createSkillupAward(awarder, receiver, skillname, 1);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// handle projectile attacks
        /// </summary>
        /// <param name="attack">attack to handle</param>
        private void handleProjectile(Attack attack)
        {
            Position position = (Position)_PositionMapper.get(attack.Defender);

            //dont continue if this attack has no position
            if (position == null)
            {
                return;
            }

            //calculate position
            Vector2  pos    = position.Pos;
            Position newPos = new Position(pos + new Vector2(rand.Next(16) + 8, 0), Vector2.Zero);

            //get equipment
            Equipment attEquip = (Equipment)_EquipmentMapper.get(attack.Attacker);
            Equipment defEquip = (Equipment)_EquipmentMapper.get(attack.Defender);

            //dont continue if we have no equipment to use
            if (attEquip == null || defEquip == null)
            {
                return;
            }

            //get weapon and armor
            Item weapon = (Item)_ItemMapper.get(attEquip.RangedWeapon);
            Item armor  = (Item)_ItemMapper.get(defEquip.Armor);

            //dont continue if either of these are null
            if (weapon == null || armor == null)
            {
                return;
            }

            //get attributes
            Statistics attAttr = (Statistics)_AttributeMapper.get(attack.Attacker);
            Statistics defAttr = (Statistics)_AttributeMapper.get(attack.Defender);

            //dont continue if either of these are null
            if (attAttr == null || defAttr == null)
            {
                return;
            }

            int perception = attAttr.Perception.Value;
            int quickness  = defAttr.Quickness.Value;
            int focus      = attAttr.Focus.Value;
            int endurance  = defAttr.Endurance.Value;

            //get Experience
            Knowledges attKnw = (Knowledges)_KnowledgeMapper.get(attack.Attacker);
            Knowledges defKnw = (Knowledges)_KnowledgeMapper.get(attack.Defender);

            //dont continue if null
            if (attKnw == null || defKnw == null)
            {
                return;
            }

            //get Skills
            Skills attSkills = (Skills)_SkillMapper.get(attack.Attacker);
            Skills defSkills = (Skills)_SkillMapper.get(attack.Defender);

            //dont continue if either of these are null
            if (attSkills == null || defSkills == null)
            {
                return;
            }

            int atkSkill = attSkills.Ranged.Value;
            int defSkill = defSkills.Avoidance.Value;


            Information infoDef = (Information)_InfoMapper.get(attack.Defender);
            Information infoAtk = (Information)_InfoMapper.get(attack.Attacker);

            //dont continue if you dont have info
            if (infoDef == null || infoAtk == null)
            {
                return;
            }

            float probHit = atkSkill / 4 + perception / 4 + attKnw.GeneralKnowledge[infoDef.GeneralGroup].Value + weapon.Speed;
            float probDef = defSkill / 4 + quickness / 4 + defKnw.GeneralKnowledge[infoAtk.GeneralGroup].Value + armor.Mobility;

            float hitProb = (probHit / (probHit + probDef)) * 1.75f + (probDef / (probHit + probDef)) * 0.15f;

            float toHit = (float)rand.NextDouble();

            int damage = 0;

            if (toHit < hitProb)
            {
                float overhit = 0f;

                if (hitProb > 1f)
                {
                    overhit = hitProb - 1f;
                }

                //int maxDmg = (int)((overhit + 1f) * ((atkSkill / 5 + focus / 4) / (endurance / 10)) * (weapon.Lethality / armor.Mitigation));
                int maxDmg = (int)((overhit + 1f) * ((atkSkill / 5 + focus / 4)) * (weapon.Lethality / armor.Mitigation)) - (endurance / 10);

                damage = rand.Next(maxDmg / 2, maxDmg);

                if (damage < 0)
                {
                    damage = 0;
                }
            }

            UtilFactory.createDirectDamage(damage, weapon.DamageType, attack.Defender, newPos);

            //create the floating dmg
            if (damage == 0)
            {
                UIFactory.createFloatingText("MISS", "DAMAGE", Color.White, 500, new Position(newPos.Pos, newPos.Offset));
            }
            else
            {
                UIFactory.createFloatingText("" + damage, "DAMAGE", Color.Yellow, 500, new Position(newPos.Pos, newPos.Offset));
            }


            Interactable interactor = (Interactable)_InteractMapper.get(attack.Attacker);
            Interactable interactee = (Interactable)_InteractMapper.get(attack.Defender);

            //only do if interaction supported
            if (interactor != null && interactor != null)
            {
                //only skill-up if you can
                if (interactor.SupportedInteractions.MAY_ADVANCE &&
                    interactee.SupportedInteractions.CAUSES_ADVANCEMENT)
                {
                    //if still possible to skill-up
                    if (atkSkill < defSkill)
                    {
                        if (rand.NextDouble() <= ((double)(defSkill - atkSkill) / (double)defSkill) * GameConfig.AwardDefs.SkillChance)
                        {
                            UtilFactory.createSkillupAward(attack.Defender, attack.Attacker, SkillName.RANGED, GameConfig.AwardDefs.SkillMinimum);
                        }
                    }

                    if (perception < quickness)
                    {
                        if (rand.NextDouble() <= ((double)(quickness - perception) / (double)quickness) * GameConfig.AwardDefs.StatChance)
                        {
                            UtilFactory.createAttributeAward(attack.Defender, attack.Attacker, StatType.PERCEPTION, GameConfig.AwardDefs.StatMinimum);
                        }
                    }

                    if (focus < endurance)
                    {
                        if (rand.NextDouble() <= ((double)(endurance - focus) / (double)endurance) * GameConfig.AwardDefs.StatChance)
                        {
                            UtilFactory.createAttributeAward(attack.Defender, attack.Attacker, StatType.FOCUS, GameConfig.AwardDefs.StatMinimum);
                        }
                    }
                }

                if (interactor.SupportedInteractions.CAUSES_ADVANCEMENT &&
                    interactee.SupportedInteractions.MAY_ADVANCE)
                {
                    //if still possible to skill-up
                    if (defSkill < atkSkill)
                    {
                        if (rand.NextDouble() <= ((double)(atkSkill - defSkill) / (double)atkSkill) * GameConfig.AwardDefs.SkillChance)
                        {
                            UtilFactory.createSkillupAward(attack.Attacker, attack.Defender, SkillName.AVOIDANCE, GameConfig.AwardDefs.SkillMinimum);
                        }
                    }

                    if (quickness < perception)
                    {
                        if (rand.NextDouble() <= ((double)(perception - quickness) / (double)perception) * GameConfig.AwardDefs.StatChance)
                        {
                            UtilFactory.createAttributeAward(attack.Attacker, attack.Defender, StatType.QUICKNESS, GameConfig.AwardDefs.StatMinimum);
                        }
                    }


                    if (endurance < focus)
                    {
                        if (rand.NextDouble() <= ((double)(focus - endurance) / (double)focus) * GameConfig.AwardDefs.StatChance)
                        {
                            UtilFactory.createAttributeAward(attack.Attacker, attack.Defender, StatType.ENDURANCE, GameConfig.AwardDefs.StatMinimum);
                        }
                    }
                }
            }

            //remove attack
            ecs_instance.delete_entity(_CurrentEntity);
        }