Exemple #1
0
 public static Action <Hero> AddKnowledge(Knowledges knowledge)
 {
     return(hero =>
     {
         hero.AddKnowledge(knowledge);
     });
 }
Exemple #2
0
 public static Action <Hero> AddKnowledge(Knowledges knowledge, uint koef)
 {
     return(hero =>
     {
         hero.SetKnowledge(knowledge, koef);
     });
 }
Exemple #3
0
        internal void RewriteKnowledges(Dictionary <string, uint> newKnowledges)
        {
            var allKnowledges = newKnowledges.Where(t => t.Value > 0).Select(t =>
            {
                Knowledges knowledge;
                var knowledgeExist = Knowledges.TryParse(t.Key, true, out knowledge);
                return(new
                {
                    t.Key,
                    KnKey = knowledge,
                    KnowledgeExist = knowledgeExist,
                    t.Value
                });
            }).ToList();

            _knowledgeses = allKnowledges.Where(t => t.KnowledgeExist).ToDictionary(t => t.KnKey, t => t.Value);
            _knowledgeses[Knowledges.Nothing] = 100;

            _ObjectKnowledgeses = _ObjectKnowledgeses.Join(allKnowledges.Where(t => !t.KnowledgeExist), t => t.Key, u => u.Key,
                                                           (pair, kn) => new KeyValuePair <string, uint>(pair.Key, kn.Value))
                                  .ToDictionary(pair => pair.Key, pair => pair.Value);

            HeroLifeCycle.NextGen();

            _stateQueue.Clear();
            StateEvent.FireEvent();
        }
        public async Task OnGetAsync()
        {
            //wheres my session at
            await HttpContext.Session.LoadAsync();

            //read serialized object from session variable
            var serializedin = HttpContext.Session.GetString(SerializedCompetencyJSONKey);

            //save it to Cbvm
            Cbvm = JsonSerializer.Deserialize <CompetencyBuilderViewModel>(serializedin);
            _logger.LogInformation($"CBVM: {serializedin.ToString()}");
            //fill my variables with the session contents
            CompetencyName        = Cbvm.CompetencyName;
            CompetencyDescription = Cbvm.CompetencyDescription;
            DispositionIndicies   = Cbvm.DispositionIndicies;
            KSPairsIndicies       = Cbvm.KSPairsIndicies;
            var repoDisp = _UOW.GetRepositoryAsync <Disposition>();
            var repoK    = _UOW.GetRepositoryAsync <KnowledgeElement>();
            var repoS    = _UOW.GetRepositoryAsync <SkillLevel>();
            IEnumerable <Disposition> tempDispList = await repoDisp.GetListAsync();

            IEnumerable <KnowledgeElement> tempKnowledgeList = await repoK.GetListAsync();

            IEnumerable <SkillLevel> tempSkillList = await repoS.GetListAsync();

            foreach (var disp in tempDispList)
            {
                foreach (var dispIndices in DispositionIndicies)
                {
                    if (disp.Id == dispIndices)
                    {
                        _logger.LogInformation("Adding a DISP");
                        DispositionList.Add(disp);
                    }
                }
            }
            foreach (var know in tempKnowledgeList)
            {
                for (int i = 0; i < KSPairsIndicies.Length; i++)
                {
                    if (know.Id == KSPairsIndicies[i][0])
                    {
                        _logger.LogInformation("Adding a KNOWL");
                        Knowledges.Add(know);
                    }
                }
            }
            foreach (var skillElement in tempSkillList)
            {
                for (int i = 0; i < KSPairsIndicies.Length; i++)
                {
                    if (skillElement.Id == KSPairsIndicies[i][1])
                    {
                        _logger.LogInformation("Adding a SKILL");
                        Skills.Add(skillElement);
                    }
                }
            }
        }
Exemple #5
0
 public void SetKnowledge(Knowledges knowledge, uint koef)
 {
     if (_knowledgeses.ContainsKey(knowledge))
     {
         var prevKnowledge = _knowledgeses[knowledge];
         _knowledgeses[knowledge] = Math.Min(100, _knowledgeses[knowledge] + koef);
         _expirience += _knowledgeses[knowledge] - prevKnowledge;
     }
     else
     {
         _knowledgeses[knowledge] = Math.Min(100, koef);
         _expirience += _knowledgeses[knowledge];
     }
 }
        private bool Accept(Window window)
        {
            window.DialogResult = true;
            window.Close();

            var copy = Knowledges.FirstOrDefault(u => u.Technology == Knowledge.Technology && u.Language == Knowledge.Language);

            if (copy != null)
            {
                Knowledge = copy;
            }

            _eventAggregator.GetEvent <AddKnowledgePubEvent>().Publish(Knowledge);

            return(true);
        }
Exemple #7
0
        public void createFollower(Vector2 position, Entity target, float distance)
        {
            Entity e = ecs_instance.create();

            ecs_instance.add_component(e, new Position(position, new Vector2(16)));
            ecs_instance.add_component(e, new Velocity(4f));
            ecs_instance.add_component(e, new Sprite("characters\\herr_von_speck_sheet", "characters\\normals\\herr_von_speck_sheet_normals", 32, 32, 0, 0));
            ecs_instance.add_component(e, new AiBehavior(new FollowerBehavior(e, target, distance, ecs_instance)));         //new FollowPath(e, target, distance, n_EcsInstance)));
            ecs_instance.add_component(e, new MapCollidable());
            ecs_instance.add_component(e, new Heading());
            ecs_instance.add_component(e, new Transform());
            ecs_instance.add_component(e, new Aggrivation());
            ecs_instance.add_component(e, new APath());

            /*
             * //setup pathing agent
             * BusAgent busAgent = new BusAgent();
             * busAgent.Agent = new Agent();
             * busAgent.Agent.Entity = e;
             *
             * Activity activity = new Activity();
             * activity.ActivityName = "activity1";
             * activity.ComponentName = "PATH_FINDER";
             * activity.InitialActivity = true;
             * activity.NextActivity = "activity1";
             *
             * AgentProcess process = new AgentProcess();
             * process.ProcessName = "path process";
             * process.Activities.Add(activity.ActivityName, activity);
             *
             * busAgent.Agent.AgentProcess = process;
             *
             * n_ECSInstance.entity_manager.add_component(e, busAgent);
             */

            //create info
            Information info = new Information();

            info.Name           = "TEST FOLLOWER";
            info.GeneralGroup   = "BAT";
            info.VariationGroup = "NONE";
            info.UniqueGroup    = "NONE";
            ecs_instance.add_component(e, info);

            //create life
            Life life = new Life();

            life.IsAlive        = true;
            life.DeathLongevity = 500;
            ecs_instance.add_component(e, life);

            //create interactions
            Interactable interact = new Interactable();

            interact.SupportedInteractions.PROJECTILE_COLLIDABLE = true;
            interact.SupportedInteractions.ATTACKABLE            = true;
            interact.SupportedInteractions.MELEE_ACTIONABLE      = true;
            interact.SupportedInteractions.AWARDS_VICTORY        = true;
            interact.SupportedInteractions.CAUSES_ADVANCEMENT    = true;
            interact.SupportedInteractions.MAY_ADVANCE           = false;
            ecs_instance.add_component(e, interact);

            //create test equipment
            ItemFactory iFactory = new ItemFactory(ecs_instance);

            ecs_instance.add_component(e, iFactory.createTestEquipment());

            int skillLevel = 25;

            //setup experiences
            Knowledges knowledges = new Knowledges();

            knowledges.GeneralKnowledge.Add("HUMAN", new Knowledge {
                Name = "", Value = skillLevel, KnowledgeType = KnowledgeType.General
            });
            knowledges.GeneralKnowledge.Add("BAT", new Knowledge {
                Name = "", Value = skillLevel, KnowledgeType = KnowledgeType.General
            });
            knowledges.VariationKnowledge.Add("NONE", new Knowledge {
                Name = "", Value = 0f, KnowledgeType = KnowledgeType.General
            });
            knowledges.UniqueKnowledge.Add("NONE", new Knowledge {
                Name = "", Value = 0f, KnowledgeType = KnowledgeType.General
            });
            ecs_instance.add_component(e, knowledges);

            //setup attributes
            Statistics statistics = new Statistics();

            statistics.Focus = new Statistic {
                Name = "FOCUS", Value = skillLevel, StatType = StatType.FOCUS
            };
            statistics.Endurance = new Statistic {
                Name = "ENDURANCE", Value = skillLevel, StatType = StatType.ENDURANCE
            };
            statistics.Mind = new Statistic {
                Name = "MIND", Value = skillLevel, StatType = StatType.MIND
            };
            statistics.Muscle = new Statistic {
                Name = "MUSCLE", Value = skillLevel, StatType = StatType.MUSCLE
            };
            statistics.Perception = new Statistic {
                Name = "PERCEPTION", Value = skillLevel, StatType = StatType.PERCEPTION
            };
            statistics.Personality = new Statistic {
                Name = "PERSONALITY", Value = skillLevel, StatType = StatType.PERSONALITY
            };
            statistics.Quickness = new Statistic {
                Name = "QUICKNESS", Value = skillLevel, StatType = StatType.QUICKNESS
            };
            ecs_instance.add_component(e, statistics);

            //create health
            Health health = new Health(statistics.Endurance.Value * 3);

            health.RecoveryAmmount = statistics.Endurance.Value / 5;
            health.RecoveryRate    = 1000;
            ecs_instance.add_component(e, health);

            //setup skills
            Skills skills = new Skills();

            skills.Ranged = new Skill {
                Name = "RANGED", Value = skillLevel, SkillType = SkillType.Offensive
            };
            skills.Avoidance = new Skill {
                Name = "AVOIDANCE", Value = skillLevel, SkillType = SkillType.Defensive
            };
            skills.Melee = new Skill {
                Name = "MELEE", Value = skillLevel, SkillType = SkillType.Offensive
            };
            ecs_instance.add_component(e, skills);

            Factions factions = new Factions();

            factions.OwnerFaction = new Faction {
                Name = "ALLY", Value = 100, FactionType = FactionType.Ally
            };
            factions.KnownFactions.Add("WILDERNESS", new Faction {
                Name = "WILDERNESS", Value = -10, FactionType = FactionType.Wilderness
            });
            factions.KnownFactions.Add("PLAYER", new Faction {
                Name = "PLAYER", Value = 100, FactionType = FactionType.Player
            });
            ecs_instance.add_component(e, factions);


            ecs_instance.add_component(e, EntityFactory.createLight(true, 3, new Vector3(position, 10), 0.5f, new Vector4(1, 1, 1, 1)));


            ecs_instance.resolve(e);
        }
Exemple #8
0
        public Entity createCharacter(CharacterDef characterDef, Vector2 position)
        {
            Entity e = ecs_instance.create();

            ecs_instance.add_component(e, new Position(position, new Vector2(16)));
            ecs_instance.add_component(e, new Velocity(3f));
            ecs_instance.add_component(e, new AiBehavior(new WanderingEnemyBehavior(e, ecs_instance)));
            ecs_instance.add_component(e, new MapCollidable());
            ecs_instance.add_component(e, new Heading());
            ecs_instance.add_component(e, new Transform());
            ecs_instance.add_component(e, new Aggrivation());


            //create avatar
            ecs_instance.add_component(e, AnimationFactory.createAvatar(characterDef.AvatarDef.Name));

            //create info
            Information info = new Information();

            info.Name           = characterDef.InfoDef.Name;
            info.GeneralGroup   = characterDef.InfoDef.GeneralGroup;
            info.VariationGroup = characterDef.InfoDef.VariationGroup;
            info.UniqueGroup    = characterDef.InfoDef.UniqueGroup;
            ecs_instance.add_component(e, info);

            //create life
            Life life = new Life();

            life.IsAlive        = true;
            life.DeathLongevity = characterDef.LifeDef.DeathLongevity;
            ecs_instance.add_component(e, life);

            //create interactions
            Interactable interact = new Interactable();

            interact.SupportedInteractions = characterDef.SupportedInteractions;
            ecs_instance.add_component(e, interact);

            //create test equipment
            //FIXME:
            ItemFactory iFactory = new ItemFactory(ecs_instance);

            ecs_instance.add_component(e, iFactory.createTestEquipment());

            //setup knowledges
            Knowledges knowledges = new Knowledges();

            foreach (Knowledge knowledge in characterDef.KnowledgesDef.GeneralKnowledges)
            {
                Knowledge k = knowledge;
                k.Value = characterDef.SkillLevel;
                knowledges.GeneralKnowledge.Add(knowledge.Name, k);
            }

            foreach (Knowledge knowledge in characterDef.KnowledgesDef.VariationKnowledges)
            {
                knowledges.VariationKnowledge.Add(knowledge.Name, knowledge);
            }

            foreach (Knowledge knowledge in characterDef.KnowledgesDef.UniqueKnowledges)
            {
                knowledges.UniqueKnowledge.Add(knowledge.Name, knowledge);
            }
            ecs_instance.add_component(e, knowledges);

            //setup attributes
            Statistics statistics = new Statistics();

            statistics.Endurance         = characterDef.StatisticsDef.Endurance;
            statistics.Endurance.Value   = characterDef.SkillLevel;
            statistics.Focus             = characterDef.StatisticsDef.Focus;
            statistics.Focus.Value       = characterDef.SkillLevel;
            statistics.Mind              = characterDef.StatisticsDef.Mind;
            statistics.Mind.Value        = characterDef.SkillLevel;
            statistics.Muscle            = characterDef.StatisticsDef.Muscle;
            statistics.Muscle.Value      = characterDef.SkillLevel;
            statistics.Perception        = characterDef.StatisticsDef.Perception;
            statistics.Perception.Value  = characterDef.SkillLevel;
            statistics.Personality       = characterDef.StatisticsDef.Personality;
            statistics.Personality.Value = characterDef.SkillLevel;
            statistics.Quickness         = characterDef.StatisticsDef.Quickness;
            statistics.Quickness.Value   = characterDef.SkillLevel;
            ecs_instance.add_component(e, statistics);

            //create health
            Health health = new Health(statistics.Endurance.Value * 3);

            health.RecoveryAmmount = statistics.Endurance.Value / 5;
            health.RecoveryRate    = 1000;
            ecs_instance.add_component(e, health);

            //setup skills
            Skills skills = new Skills();

            skills.Avoidance       = characterDef.SkillsDef.Avoidance;
            skills.Melee           = characterDef.SkillsDef.Melee;
            skills.Ranged          = characterDef.SkillsDef.Ranged;
            skills.Ranged.Value    = characterDef.SkillLevel;
            skills.Avoidance.Value = characterDef.SkillLevel;
            skills.Melee.Value     = characterDef.SkillLevel;
            ecs_instance.add_component(e, skills);

            //setup factions
            Factions factions = new Factions();

            factions.OwnerFaction = characterDef.FactionsDef.OwnerFaction;
            foreach (Faction faction in characterDef.FactionsDef.Factions)
            {
                factions.KnownFactions.Add(faction.Name, faction);
            }
            ecs_instance.add_component(e, factions);

            Aggrivation aggro = new Aggrivation();

            ecs_instance.add_component(e, aggro);

            ecs_instance.add_component(e, EntityFactory.createLight(true, 3, new Vector3(position, 10), 0.5f, new Vector4(1, 1, .6f, 1)));

            ecs_instance.group_manager.add_entity_to_group("WANDERERS", e);

            ecs_instance.resolve(e);

            return(e);
        }
Exemple #9
0
        public void createBatEnemy(Vector2 position, int skillLevel)
        {
            Entity e = ecs_instance.create();

            ecs_instance.add_component(e, new Position(position, new Vector2(16)));
            ecs_instance.add_component(e, new Velocity(3f));
            ecs_instance.add_component(e, new AiBehavior(new WanderingEnemyBehavior(e, ecs_instance)));
            ecs_instance.add_component(e, new MapCollidable());
            ecs_instance.add_component(e, new Heading());
            ecs_instance.add_component(e, new Transform());
            ecs_instance.add_component(e, new Aggrivation());
            ecs_instance.add_component(e, AnimationFactory.createAvatar("BAT"));

            //create info
            Information info = new Information();

            info.Name           = "TEST WANDERER";
            info.GeneralGroup   = "BAT";
            info.VariationGroup = "NONE";
            info.UniqueGroup    = "NONE";
            ecs_instance.add_component(e, info);

            //create life
            Life life = new Life();

            life.IsAlive        = true;
            life.DeathLongevity = 500;
            ecs_instance.add_component(e, life);

            //create interactions
            Interactable interact = new Interactable();

            interact.SupportedInteractions.PROJECTILE_COLLIDABLE = true;
            interact.SupportedInteractions.ATTACKABLE            = true;
            interact.SupportedInteractions.MELEE_ACTIONABLE      = true;
            interact.SupportedInteractions.AWARDS_VICTORY        = true;
            interact.SupportedInteractions.CAUSES_ADVANCEMENT    = true;
            interact.SupportedInteractions.MAY_ADVANCE           = false;
            ecs_instance.add_component(e, interact);

            //create test equipment
            ItemFactory iFactory = new ItemFactory(ecs_instance);

            ecs_instance.add_component(e, iFactory.createTestEquipment());

            //setup experiences
            Knowledges knowledges = new Knowledges();

            knowledges.GeneralKnowledge.Add("HUMAN", new Knowledge {
                Name = "", Value = skillLevel, KnowledgeType = KnowledgeType.General
            });
            knowledges.GeneralKnowledge.Add("BAT", new Knowledge {
                Name = "", Value = skillLevel, KnowledgeType = KnowledgeType.General
            });
            knowledges.VariationKnowledge.Add("NONE", new Knowledge {
                Name = "", Value = 0f, KnowledgeType = KnowledgeType.General
            });
            knowledges.UniqueKnowledge.Add("NONE", new Knowledge {
                Name = "", Value = 0f, KnowledgeType = KnowledgeType.General
            });
            ecs_instance.add_component(e, knowledges);

            //setup attributes
            Statistics statistics = new Statistics();

            statistics.Focus = new Statistic {
                Name = "FOCUS", Value = skillLevel, StatType = StatType.FOCUS
            };
            statistics.Endurance = new Statistic {
                Name = "ENDURANCE", Value = skillLevel, StatType = StatType.ENDURANCE
            };
            statistics.Mind = new Statistic {
                Name = "MIND", Value = skillLevel, StatType = StatType.MIND
            };
            statistics.Muscle = new Statistic {
                Name = "MUSCLE", Value = skillLevel, StatType = StatType.MUSCLE
            };
            statistics.Perception = new Statistic {
                Name = "PERCEPTION", Value = skillLevel, StatType = StatType.PERCEPTION
            };
            statistics.Personality = new Statistic {
                Name = "PERSONALITY", Value = skillLevel, StatType = StatType.PERSONALITY
            };
            statistics.Quickness = new Statistic {
                Name = "QUICKNESS", Value = skillLevel, StatType = StatType.QUICKNESS
            };
            ecs_instance.add_component(e, statistics);

            //create health
            Health health = new Health(statistics.Endurance.Value * 3);

            health.RecoveryAmmount = statistics.Endurance.Value / 5;
            health.RecoveryRate    = 1000;
            ecs_instance.add_component(e, health);

            //setup skills
            Skills skills = new Skills();

            skills.Ranged = new Skill {
                Name = "RANGED", Value = skillLevel, SkillType = SkillType.Offensive
            };
            skills.Avoidance = new Skill {
                Name = "AVOIDANCE", Value = skillLevel, SkillType = SkillType.Defensive
            };
            skills.Melee = new Skill {
                Name = "MELEE", Value = skillLevel, SkillType = SkillType.Offensive
            };
            ecs_instance.add_component(e, skills);

            //setup factions
            Factions factions = new Factions();

            factions.OwnerFaction = new Faction {
                Name = "WILDERNESS", Value = 100, FactionType = FactionType.Wilderness
            };
            factions.KnownFactions.Add("PLAYER", new Faction {
                Name = "PLAYER", Value = -10, FactionType = FactionType.Player
            });
            factions.KnownFactions.Add("ALLY", new Faction {
                Name = "ALLY", Value = -10, FactionType = FactionType.Ally
            });
            ecs_instance.add_component(e, factions);

            Aggrivation aggro = new Aggrivation();

            ecs_instance.add_component(e, aggro);

            ecs_instance.add_component(e, EntityFactory.createLight(true, 3, new Vector3(position, 10), 0.5f, new Vector4(1, 1, .6f, 1)));

            ecs_instance.group_manager.add_entity_to_group("WANDERERS", e);

            ecs_instance.resolve(e);
        }
Exemple #10
0
        public double GetKnowledge(Knowledges knowledge)
        {
            uint koef;

            return(_knowledgeses.TryGetValue(knowledge, out koef) ? koef / 100.0 : 0.0);
        }
Exemple #11
0
 public bool HasKnowledge(Knowledges knowledge)
 {
     return(_knowledgeses.ContainsKey(knowledge));
 }
Exemple #12
0
 public void AddKnowledge(Knowledges knowledge)
 {
     SetKnowledge(knowledge, 1);
 }
Exemple #13
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);
        }
Exemple #14
0
        /// <summary>
        /// awards a victory
        /// </summary>
        /// <param name="entity"></param>
        private void awardVictory(Award award)
        {
            //retrieve knowledges
            Knowledges awarder  = (Knowledges)v_KnowledgeMapper.get(award.Awarder);
            Knowledges receiver = (Knowledges)v_KnowledgeMapper.get(award.Receiver);

            //if either is not available, don't continue
            if (awarder == null || receiver == null)
            {
                return;
            }

            //retrieve creature information
            Information info = (Information)v_InfoMapper.get(award.Awarder);

            //cant continue if no info
            if (info == null)
            {
                return;
            }

            //look up skills/knowledge
            Knowledge awdGeneral  = awarder.GeneralKnowledge[info.GeneralGroup];
            Knowledge awdVaration = awarder.VariationKnowledge[info.VariationGroup];
            Knowledge awdUnique   = awarder.UniqueKnowledge[info.UniqueGroup];

            Knowledge recGeneral  = receiver.GeneralKnowledge[info.GeneralGroup];
            Knowledge recVaration = receiver.VariationKnowledge[info.VariationGroup];
            Knowledge recUnique   = receiver.UniqueKnowledge[info.UniqueGroup];

            //reward general
            if (recGeneral.Value < awdGeneral.Value)
            {
                //calculate reward
                float val = ((awdGeneral.Value - recGeneral.Value) / awdGeneral.Value) * award.MaxAwardable;

                if (val < award.MinAwardable)
                {
                    val = award.MinAwardable;
                }

                recGeneral.Value += val;
                receiver.GeneralKnowledge.Remove(info.GeneralGroup);
                receiver.GeneralKnowledge.Add(info.GeneralGroup, recGeneral);

                //announce reward
                Position pos = (Position)v_PositionMapper.get(award.Receiver);
                if (pos != null)
                {
                    UIFactory.createFloatingText("+" + val.ToString("#.0") + " [" + info.GeneralGroup.ToString() + "]", "GENERAL", Color.MediumPurple, 1000, new Position(pos.Pos, pos.Offset));
                }
            }
            //reward variation
            if (recVaration.Value < awdVaration.Value)
            {
                //calculate reward
                float val = ((awdVaration.Value - recVaration.Value) / awdVaration.Value) * award.MaxAwardable;

                if (val < award.MinAwardable)
                {
                    val = award.MinAwardable;
                }

                recVaration.Value += val;
                receiver.VariationKnowledge.Remove(info.VariationGroup);
                receiver.VariationKnowledge.Add(info.VariationGroup, recVaration);

                //announce reward
                Position pos = (Position)v_PositionMapper.get(award.Receiver);
                if (pos != null)
                {
                    UIFactory.createFloatingText("+" + val.ToString("#.0") + " [" + info.VariationGroup.ToString() + "]", "GENERAL", Color.MediumPurple, 1000, new Position(pos.Pos, pos.Offset));
                }
            }
            //reward unique
            if (recUnique.Value < awdUnique.Value)
            {
                //calculate reward
                float val = ((awdUnique.Value - recUnique.Value) / awdUnique.Value) * award.MaxAwardable;

                if (val < award.MinAwardable)
                {
                    val = award.MinAwardable;
                }

                recUnique.Value += val;
                receiver.UniqueKnowledge.Remove(info.UniqueGroup);
                receiver.UniqueKnowledge.Add(info.UniqueGroup, recUnique);

                //announce reward
                Position pos = (Position)v_PositionMapper.get(award.Receiver);
                if (pos != null)
                {
                    UIFactory.createFloatingText("+" + val.ToString("#.0") + " [" + info.UniqueGroup.ToString() + "]", "GENERAL", Color.MediumPurple, 1000, new Position(pos.Pos, pos.Offset));
                }
            }
        }
Exemple #15
0
        public static Entity createPlayer(int skillLevel)
        {
            Entity e = ecs_instance.create();

            GameMap gameMap = ComponentMapper.get <GameMap> (ecs_instance.tag_manager.get_entity_by_tag("MAP"));
            Vector2 pos     = MapFactory.findSafeLocation(gameMap);

            //ECSInstance.entity_manager.add_component(e, new Position(new Vector2(576f, 360f),new Vector2(12.5f)));
            ecs_instance.add_component(e, new Position(pos, new Vector2(16)));
            //ECSInstance.entity_manager.add_component(e, new Position(new Vector2(0, 0), new Vector2(12.5f)));
            ecs_instance.add_component(e, new Velocity(4f));
            ecs_instance.add_component(e, new Controllable());
            //ECSInstance.entity_manager.add_component(e, new Sprite("characters\\lor_lar_sheet", "characters\\normals\\lor_lar_sheet_normals",32,32,0,0));;

            ecs_instance.add_component(e, AnimationFactory.createPlayerAnimation());
            ecs_instance.add_component(e, new CameraFocus(75));
            ecs_instance.add_component(e, new MapCollidable());
            ecs_instance.add_component(e, new Heading());
            ecs_instance.add_component(e, createLight(true, 8, new Vector3(new Vector2(576f, 360f), 10), 0.5f, new Vector4(1, 1, .6f, 1)));
            ecs_instance.add_component(e, new Transform());

            Information info = new Information();

            info.GeneralGroup   = "HUMAN";
            info.VariationGroup = "NONE";
            info.UniqueGroup    = "NONE";
            info.Name           = "PLAYER";
            ecs_instance.add_component(e, info);

            //create life
            Life life = new Life();

            life.IsAlive        = true;
            life.DeathLongevity = 1000;
            ecs_instance.add_component(e, life);

            //create interactions
            Interactable interact = new Interactable();

            interact.SupportedInteractions.PROJECTILE_COLLIDABLE = true;
            interact.SupportedInteractions.ATTACKABLE            = true;
            interact.SupportedInteractions.MAY_RECEIVE_VICTORY   = true;
            interact.SupportedInteractions.MAY_ADVANCE           = true;
            interact.SupportedInteractions.CAUSES_ADVANCEMENT    = false;
            interact.SupportedInteractions.AWARDS_VICTORY        = false;
            ecs_instance.add_component(e, interact);

            //create test equipment
            ItemFactory iFactory = new ItemFactory(ecs_instance);

            ecs_instance.add_component(e, iFactory.createTestEquipment());

            //setup experiences
            Knowledges knowledges = new Knowledges();

            knowledges.GeneralKnowledge.Add("HUMAN", new Knowledge {
                Name = "", Value = skillLevel, KnowledgeType = KnowledgeType.General
            });
            knowledges.GeneralKnowledge.Add("BAT", new Knowledge {
                Name = "", Value = skillLevel, KnowledgeType = KnowledgeType.General
            });
            knowledges.VariationKnowledge.Add("NONE", new Knowledge {
                Name = "", Value = 0f, KnowledgeType = KnowledgeType.General
            });
            knowledges.UniqueKnowledge.Add("NONE", new Knowledge {
                Name = "", Value = 0f, KnowledgeType = KnowledgeType.General
            });
            ecs_instance.add_component(e, knowledges);

            //setup attributes
            Statistics statistics = new Statistics();

            statistics.Focus = new Statistic {
                Name = "FOCUS", Value = skillLevel, StatType = StatType.FOCUS
            };
            statistics.Endurance = new Statistic {
                Name = "ENDURANCE", Value = skillLevel, StatType = StatType.ENDURANCE
            };
            statistics.Mind = new Statistic {
                Name = "MIND", Value = skillLevel, StatType = StatType.MIND
            };
            statistics.Muscle = new Statistic {
                Name = "MUSCLE", Value = skillLevel, StatType = StatType.MUSCLE
            };
            statistics.Perception = new Statistic {
                Name = "PERCEPTION", Value = skillLevel, StatType = StatType.PERCEPTION
            };
            statistics.Personality = new Statistic {
                Name = "PERSONALITY", Value = skillLevel, StatType = StatType.PERSONALITY
            };
            statistics.Quickness = new Statistic {
                Name = "QUICKNESS", Value = skillLevel, StatType = StatType.QUICKNESS
            };
            ecs_instance.add_component(e, statistics);

            //create health
            Health health = new Health(statistics.Endurance.Value * 5);            // new Health(5000);//

            health.RecoveryAmmount = statistics.Endurance.Value / 5;
            health.RecoveryRate    = 1000;
            ecs_instance.add_component(e, health);

            //setup skills
            Skills skills = new Skills();

            skills.Ranged = new Skill {
                Name = "RANGED", Value = skillLevel, SkillType = SkillType.Offensive
            };
            skills.Avoidance = new Skill {
                Name = "AVOIDANCE", Value = skillLevel, SkillType = SkillType.Defensive
            };
            skills.Melee = new Skill {
                Name = "MELEE", Value = skillLevel, SkillType = SkillType.Offensive
            };
            ecs_instance.add_component(e, skills);

            Factions factions = new Factions();

            factions.OwnerFaction = new Faction {
                Name = "PLAYER", Value = 100, FactionType = FactionType.Player
            };
            factions.KnownFactions.Add("WILDERNESS", new Faction {
                Name = "WILDERNESS", Value = -10, FactionType = FactionType.Wilderness
            });
            factions.KnownFactions.Add("ALLY", new Faction {
                Name = "ALLY", Value = 100, FactionType = FactionType.Ally
            });
            ecs_instance.add_component(e, factions);

            GameSession.PlayerState              = new PlayerState();
            GameSession.PlayerState.Statistics   = statistics;
            GameSession.PlayerState.Factions     = factions;
            GameSession.PlayerState.Health       = health;
            GameSession.PlayerState.Information  = info;
            GameSession.PlayerState.Interactable = interact;
            GameSession.PlayerState.Knowledges   = knowledges;
            GameSession.PlayerState.Life         = life;
            GameSession.PlayerState.Skills       = skills;

            ecs_instance.tag_manager.tag_entity("PLAYER", e);

            ecs_instance.resolve(e);

            return(e);
        }