protected override void process(Entity entity) { //get colidable entity's position Position pos = (Position)m_PositionMapper.get(entity); ViewPort camView = (ViewPort)m_ViewPortMapper.get(m_Camera); MapCollidable mapCollide = (MapCollidable)m_MapCollidableMapper.get(entity); //reset collision detection mapCollide.Collided = false; //get the coliding entities position Vector2 colPos = pos.Pos; //create a polygon based at this entity's current position, using standard tileSize for height and width Polygon colPoly = createSquarePolygon(colPos, m_TileSize, m_TileSize); //set the center of the screen (used later for creating the the tile's polygon in "createPolysFromTiles") m_Center = camView.getDimensions() / 2; //find colliding tile polygons by finding a list of tiles that colide with the coliding entity's polygon List <Polygon> polys = createPolysFromTiles(findColidingTiles(colPoly)); //if no poly's were found return now if (polys == null) { return; } //collided mapCollide.Collided = true; Vector2 response; //for each tile polygon that we have collided with, find the heading correction vector //and update the position with it. The sum of the corrections, will resolve our position //to all collisions for (int i = 0; i < polys.Count; i++) { response = correctHeading(colPoly, polys[i]); mapCollide.ResponseVector += response; colPos += response; } //set the corrected position pos.Pos = colPos; }
protected override void process(Entity entity) { AiBehavior aiBehavior = (AiBehavior)_BehaviorMapper.get(entity); Life life = (Life)_LifeMapper.get(entity); if (life.IsAlive) { aiBehavior.Behavior.Behave(); } else { if (!aiBehavior.Behavior.IsClean) { aiBehavior.Behavior.deathCleanup(); } } }
protected override void process(Entity entity) { Position position = (Position)q_PositionMapper.get(entity); ViewPort camera = (ViewPort)q_ViewPortMapper.get(q_Camera); SpatialPartition spatial = (SpatialPartition)q_SpatialMapper.get(q_Spatial); Vector2 pos = position.Pos + position.Offset; Vector2 origin = camera.getOrigin(); QuadNode <Entity> node = spatial.QuadTree.locateNode(pos); int width = (int)(node.LRCorner.X - node.ULCorner.X); int height = (int)(node.LRCorner.Y - node.ULCorner.Y); Rectangle rec = new Rectangle((int)(node.ULCorner.X - origin.X), (int)(node.ULCorner.Y - origin.Y), width, height); _sprite_batch.Draw(q_Texture, rec, new Color(1f, 0f, 0f, 0f)); }
private static void doStaticDamage(ActionPackage aPack) { int dmg = rand.Next(aPack.ActionDef.DamageDef.Min, aPack.ActionDef.DamageDef.Max); Position pos = ComponentMapper.get <Position> (aPack.Target); UtilFactory.createDirectDamage(dmg, aPack.ActionDef.DamageDef.DamageType, aPack.Target, pos); Position newPos = new Position(pos.Pos + new Vector2(rand.Next(16) + 8, 0), Vector2.Zero); UIFactory.createFloatingText("" + dmg, "DAMAGE", DamageUtils.getDamageColor(aPack.ActionDef.DamageDef.DamageType), 500, newPos); }
/// <summary> /// finds tiles that may collide with the given polygon /// </summary> /// <param name="A">Polygon to check</param> /// <returns>a list of colliding tile index vectors</returns> private List <Vector2> findColidingTiles(Polygon A) { //setup some temp variables int x, y; List <Vector2> tiles = new List <Vector2>(); //get the tile map GameMap map = (GameMap)m_GameMapMapper.get(m_Map); Terrain terrain; //check each test point on A for a coresponding tile for (int i = 0; i < A.TestPoints.Length; i++) { //map the test point back-to the tile matrix //x = (int)((A.TestPoints[i].X + m_Center.X) / m_TileSize); //y = (int)((A.TestPoints[i].Y + m_Center.Y) / m_TileSize); x = (int)((A.TestPoints[i].X) / m_TileSize); y = (int)((A.TestPoints[i].Y) / m_TileSize); //get a potential colliding tile terrain = map.getTerrain(x, y); //ensure we have something usefull if (terrain == null) { continue; } //if tile isnt blocking, then there is no issue, try getting another if (!terrain.IsBlocking) { continue; } //make sure we didnt get this one already if (!tiles.Contains(new Vector2(x, y))) { tiles.Add(new Vector2(x, y)); } } //return our list (may or may not contain tile index vectors) return(tiles); }
private static float getSkill(Entity entity, SkillName skillname) { Skills skills = ComponentMapper.get <Skills> (entity); switch (skillname) { case SkillName.AVOIDANCE: return(skills.Avoidance.Value); case SkillName.MELEE: return(skills.Melee.Value); case SkillName.RANGED: return(skills.Ranged.Value); default: return(default(Skill).Value); } }
protected override void process(Entity entity) { Target target = (Target)t_TargetMapper.get(entity); if (target == null) { return; } if (target.TargetEntity == null) { return; } Life entityLife = (Life)t_LifeMapper.get(target.TargetEntity); if (entityLife == null) { target.Active = false; return; } if (entityLife.IsAlive) { Position targetPos = (Position)t_PositionMapper.get(entity); Position entityPos = (Position)t_PositionMapper.get(target.TargetEntity); if (entityPos == null) { return; } targetPos.Pos = entityPos.Pos; targetPos.Offset = entityPos.Offset; } else { Sprite sprite = (Sprite)t_SpriteMapper.get(entity); sprite.Visible = false; target.Active = false; target.TargetEntity = null; } }
private BehaviorReturnCode initializePathfinder() { Position start = (Position)f_PositionMapper.get(f_ThisEntity); Position finish = (Position)f_PositionMapper.get(f_Target); f_Map = s_EcsInstance.tag_manager.get_entity_by_tag("MAP"); GameMap map = (GameMap)f_GameMapMapper.get(f_Map); f_Camera = s_EcsInstance.tag_manager.get_entity_by_tag("CAMERA"); ViewPort viewport = (ViewPort)f_ViewPortMapper.get(f_Camera); f_Spatial = s_EcsInstance.tag_manager.get_entity_by_tag("SPATIAL"); SpatialPartition spatial = (SpatialPartition)f_SpatialMapper.get(f_Spatial); spatial.QuadTree.setContentAtLocation(f_ThisEntity, start.Pos); s_LastNode = spatial.QuadTree.locateNode(start.Pos); Vector2 sVec, fVec; //s_Center = viewport.getDimensions() / 2; sVec = (start.Pos) / f_TileSize; fVec = (finish.Pos + finish.Offset) / f_TileSize; /* * sVec = (start.Pos + s_Center) / s_TileSize; * fVec = (finish.Pos + s_Center) / s_TileSize; */ s_TargetCell.Position = fVec; s_CurrentCell.Position = sVec; //findPath = new FindPathAction(s_EcsInstance,sVec,fVec, map); APath path = (APath)f_PathMapper.get(f_ThisEntity); path.Start = sVec; path.Finish = fVec; path.Map = map; path.PathState = PathState.Idle; s_TargetCurrentPosition = finish.Pos + s_Offset; //convert to map position s_TargetCurrentPosition = new Vector2((int)s_TargetCurrentPosition.X / f_TileSize, (int)s_TargetCurrentPosition.Y / f_TileSize); s_TargetPreviousPosition = s_TargetCurrentPosition; f_BeginPathingAndMovement = true; return(BehaviorReturnCode.Success); }
/// <summary> /// updates the location of the control according to the location of the caller. /// </summary> /// <param name="control"></param> /// <param name="args"></param> public void updateHandler(Control control, InterfaceArgs args) { _ElapsedTime += control.ecs_instance.ElapsedTime; if (_ElapsedTime >= _Duration) { control.ecs_instance.delete_entity(control.owner); } Position pos = (Position)_PositionMapper.get(control.caller); ViewPort camera = (ViewPort)_ViewPortMapper.get(control.ecs_instance.tag_manager.get_entity_by_tag("CAMERA")); if (pos != null) { Vector2 pt = pos.Pos - camera.getOrigin(); control.bounds = new Rectangle((int)pt.X, (int)pt.Y - control.bounds.Height - 16, control.bounds.Width, control.bounds.Height); } }
protected override void process(Entity entity) { Trigger trigger = (Trigger)t_TriggerMapper.get(entity); //update delay time trigger.ElapsedTimeDelay += ecs_instance.ElapsedTime; //is the trigger ready to fire? if (trigger.ElapsedTimeDelay >= trigger.TimeDelay) { //update recurring time trigger.ElapsedTimeRecurring += ecs_instance.ElapsedTime; //if the trigger has not fired yet, fire it if (!trigger.HasFired) { trigger.IsActive = true; } //should the trigger be re-activated? if (trigger.HasFired && trigger.IsRecurring && (trigger.ElapsedTimeRecurring >= trigger.RecurrancePeriod)) { trigger.IsActive = true; trigger.ElapsedTimeRecurring = 0; } } //attempt to fire trigger if (trigger.IsActive) { trigger.fire(ecs_instance); trigger.IsActive = false; } //cleanup trigger if appropriate if ((trigger.HasFired && !trigger.IsRecurring) || trigger.KillTriggerNow) { trigger.clearAction(); ecs_instance.delete_entity(entity); } }
private static void labelUpdate(Control sender, InterfaceArgs args) { Vaerydian.Components.Characters.Skills skills = ComponentMapper.get <Vaerydian.Components.Characters.Skills>(sender.caller); Vaerydian.Components.Characters.Statistics attributes = ComponentMapper.get <Vaerydian.Components.Characters.Statistics>(sender.caller); GLabel label = (GLabel)sender; label.text = " Skills" + "\n" + " Range: " + skills.Ranged.Value + "\n" + " Melee: " + skills.Melee.Value + "\n" + " Avoidance: " + skills.Avoidance.Value + "\n" + "\n" + " Attributes" + "\n" + " Endurance: " + attributes.Endurance.Value + "\n" + " Focus: " + attributes.Focus.Value + "\n" + " Mind: " + attributes.Mind.Value + "\n" + " Muscle: " + attributes.Muscle.Value + "\n" + " Perception: " + attributes.Perception.Value + "\n" + " Personality: " + attributes.Personality.Value + "\n" + " Quickness: " + attributes.Quickness.Value; }
public void destoryEquipment(Entity entity) { ComponentMapper equipMapper = new ComponentMapper(new Equipment(), ecs_instance); ComponentMapper itemMapper = new ComponentMapper(new Item(), ecs_instance); Equipment equip = (Equipment)equipMapper.get(entity); if (equip == null) { return; } //remove melee weapon Item meleeWeapon = (Item)itemMapper.get(equip.MeleeWeapon); if (meleeWeapon != null) { ecs_instance.delete_entity(equip.MeleeWeapon); } //remove ranged weapon Item rangedWeapon = (Item)itemMapper.get(equip.RangedWeapon); if (rangedWeapon != null) { ecs_instance.delete_entity(equip.RangedWeapon); } //remove armor Item armor = (Item)itemMapper.get(equip.Armor); if (armor != null) { ecs_instance.delete_entity(equip.Armor); } return; }
protected override void process(Entity entity) { //retrieve this attack _CurrentEntity = entity; Attack attack = (Attack)_AttackMapper.get(entity); //see if defender is aggroable Aggrivation aggro = (Aggrivation)_AggroMapper.get(attack.Defender); if (aggro != null) { //set aggro if (!aggro.HateList.Contains(attack.Attacker)) { aggro.HateList.Add(attack.Attacker); } } //determine type of attack and handle it switch (attack.AttackType) { case AttackType.Melee: handleMelee(attack); break; case AttackType.Projectile: handleProjectile(attack); break; case AttackType.Ability: handleAbility(attack); break; default: ecs_instance.delete_entity(entity); break; } }
private static void doDamageAction(ActionPackage aPack) { Aggrivation aggro = ComponentMapper.get <Aggrivation> (aPack.Target); //check aggro and add if not present if (aggro != null) { if (!aggro.HateList.Contains(aPack.Owner)) { aggro.HateList.Add(aPack.Owner); } } switch (aPack.ActionDef.DamageDef.DamageBasis) { case DamageBasis.ATTRIBUTE: break; case DamageBasis.ITEM: break; case DamageBasis.NONE: break; case DamageBasis.SKILL: break; case DamageBasis.STATIC: doStaticDamage(aPack); break; case DamageBasis.WEAPON: doWeaponDamage(aPack); break; default: return; } }
protected override void ProcessEntity(Entity entity, float deltaTime) { //Debug.Log("PlayerShootingSystem ProcessEntity deltaTime = " + deltaTime); var model = _weaponsMapper.get(entity); var shooting = _shootingMapper.get(entity); if (IsFireProcess) { if (shooting.IsFirstTimeShot) { var firePoint = model.CurrentWeaponView.GetFirePoint(); Fire(model.CurrentWeaponView.FireRate, firePoint.position, firePoint.forward); shooting.IsFirstTimeShot = false; shooting.DurationTime = 0f; } shooting.DurationTime += deltaTime; if (shooting.DurationTime >= model.CurrentWeaponView.FireRate) { var firePoint = model.CurrentWeaponView.GetFirePoint(); Fire(model.CurrentWeaponView.FireRate, firePoint.position, firePoint.forward); shooting.DurationTime -= model.CurrentWeaponView.FireRate; } } else { if (shooting.DurationTime < model.CurrentWeaponView.FireRate) { shooting.DurationTime += deltaTime; } if (!shooting.IsFirstTimeShot && shooting.DurationTime > model.CurrentWeaponView.FireRate) { shooting.IsFirstTimeShot = true; } } }
public static void attemptStatAward(Entity receiver, Entity awarder, float rStat, float aStat, StatType stattype, 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 (rStat < aStat) { if (rand.NextDouble() <= ((double)(aStat - rStat) / (double)aStat) * 0.5) { UtilFactory.createAttributeAward(awarder, receiver, stattype, 1); } } } } }
protected override void process(Entity entity) { //grab components Position position = (Position)h_PositionMapper.get(entity); ViewPort camera = (ViewPort)h_ViewportMapper.get(h_Camera); Health health = (Health)h_HealthMapper.get(entity); //get vectors for easy working Vector2 pos = position.Pos; Vector2 origin = camera.getOrigin(); //calculate current HP percentage float percentage = (float)health.CurrentHealth / (float)health.MaxHealth; //set the maximum x-distance that we have to draw, up to 32 pixels int max = (int)(32 * percentage); //construct the drawing region rectangle Rectangle rect = new Rectangle((int)(pos.X - origin.X), (int)(pos.Y - 10 - origin.Y), max, 5); //draw the health bar _sprite_batch.Draw(h_Texture, rect, Color.Red); }
protected override void process(Entity entity) { Award award = (Award)v_VictoryMapper.get(entity); //if for whatever reason either a null, return your ass if (award == null) { return; } switch (award.AwardType) { case AwardType.Victory: awardVictory(award); break; case AwardType.SkillUp: awardSkillUp(award); break; case AwardType.Attribute: awardAttributeUp(award); break; case AwardType.Health: awardHealthUp(award); break; default: break; } //end victory ecs_instance.delete_entity(entity); }
protected override void process(Entity entity) { Position focusPosition = (Position)_PositionMapper.get(entity); CameraFocus focus = (CameraFocus)_CameraFocusMapper.get(entity); ViewPort cameraView = (ViewPort)_ViewportMapper.get(_Camera); Vector2 cPos = cameraView.getOrigin(); Vector2 center = cPos + cameraView.getDimensions() / 2; Vector2 fPos = focusPosition.Pos; float dist, radius; dist = Vector2.Distance(fPos, center); radius = focus.getFocusRadius(); if (dist > radius) { Vector2 vec = Vector2.Subtract(fPos, center); vec.Normalize(); cPos += Vector2.Multiply(vec, dist - radius); cameraView.setOrigin(cPos); } }
protected override void process(Entity entity) { //get map and viewport GameMap map = (GameMap)m_GameMapMapper.get(entity); m_ViewPort = (ViewPort)m_ViewportMapper.get(m_Camera); //GeometryMap geometry = (GeometryMap)m_GeometryMapper.get(m_Geometry); //update for current viewport location/dimensions //grab key viewport info Vector2 origin = m_ViewPort.getOrigin(); Vector2 dimensions = m_ViewPort.getDimensions();// / 2; Vector2 pos; //updateView(origin, center, m_ViewPort.getDimensions()); updateView(map.Map, origin, dimensions); //iterate through current viewable tiles for (int x = m_xStart; x <= m_xFinish; x++) { for (int y = m_yStart; y <= m_yFinish; y++) { //grab current tile terrain _terrain = map.getTerrain(x, y); //ensure its useable if (_terrain == null) { continue; } //calculate position to place tile pos = new Vector2(x * m_TileSize, y * m_TileSize); //m_SpriteBatch.Draw(m_Texture, pos-origin, m_RectDict[m_Terrain.TerrainType], Color.White, 0f, new Vector2(0), new Vector2(1), SpriteEffects.None, 0f); //m_SpriteBatch.Draw(m_Texture, pos - origin, null, getColorVariation(m_Terrain), 0f, new Vector2(0), new Vector2(1), SpriteEffects.None, 0f); if (_terrain.TerrainDef.Texture == null) { _sprite_batch.Draw(m_Texture, pos - origin, null, getColorVariation(_terrain), 0f, new Vector2(0), new Vector2(1), SpriteEffects.None, 0f); continue; } _sprite_batch.Draw(m_Textures[_terrain.TerrainDef.Texture], pos - origin, null, applyLighting(_terrain), 0f, new Vector2(0), new Vector2(1), SpriteEffects.None, 0f); //reset terrain lighting _terrain.Lighting = 0.25f; } } /* * try * { * MapDebug debug = (MapDebug)m_MapDebugMapper.get(m_MapDebug); * * * if (debug.OpenSet != null) * { * for (int i = 0; i < debug.OpenSet.Size; i++) * { * if (debug.OpenSet[i] == null) * continue; * pos = debug.OpenSet[i].Data.Position * m_TileSize; * * m_SpriteBatch.Draw(m_Texture, pos-origin, m_RectDict[TerrainType.CAVE_FLOOR], Color.Orange, 0f,new Vector2(0), new Vector2(1), SpriteEffects.None, 0f); * } * } * * if (debug.Blocking != null) * { * for (int i = 0; i < debug.Blocking.Count; i++) * { * if (debug.Blocking[i] == null) * continue; * pos = debug.Blocking[i].Position * m_TileSize; * * m_SpriteBatch.Draw(m_Texture, pos - origin, m_RectDict[TerrainType.CAVE_FLOOR], Color.Red, 0f, new Vector2(0), new Vector2(1), SpriteEffects.None, 0f); * } * } * * if (debug.ClosedSet != null) * { * for (int i = 0; i < debug.ClosedSet.Count; i++) * { * if (debug.ClosedSet[i] == null) * continue; * pos = debug.ClosedSet[i].Position * m_TileSize; * * m_SpriteBatch.Draw(m_Texture, pos - origin, m_RectDict[TerrainType.CAVE_FLOOR], Color.Yellow, 0f, new Vector2(0), new Vector2(1), SpriteEffects.None, 0f); * } * } * * if (debug.Path != null) * { * for (int i = 0; i < debug.Path.Count; i++) * { * if (debug.Path[i] == null) * continue; * pos = debug.Path[i].Position * m_TileSize; * * m_SpriteBatch.Draw(m_Texture, pos - origin, m_RectDict[TerrainType.CAVE_FLOOR], Color.YellowGreen, 0f, new Vector2(0), new Vector2(1), SpriteEffects.None, 0f); * } * } * * } * catch (Exception e) * { * * }*/ }
private static float getKnowledge(Entity entity, Entity target) { Information info = ComponentMapper.get <Information> (target); return(ComponentMapper.get <Knowledges> (entity).GeneralKnowledge [info.GeneralGroup].Value); }
private static Item getArmor(Entity entity) { Equipment equip = ComponentMapper.get <Equipment> (entity); return(ComponentMapper.get <Item> (equip.Armor)); }
private static Item getWeapon(Entity entity) { Equipment equip = ComponentMapper.get <Equipment> (entity); return(ComponentMapper.get <Item> (equip.RangedWeapon)); }
/// <summary> /// checks for nearby enemy factions /// </summary> /// <returns>true if hostile was detected</returns> private bool hasDetectedHostile() { if (w_LastNode == null) { return(false); } SpatialPartition spatial = (SpatialPartition)w_SpatialMapper.get(w_Spatial); Position position = (Position)w_PositionMapper.get(w_ThisEntity); List <Entity> locals = spatial.QuadTree.findAllWithinRange(position.Pos, 100f); //nothing to detect if (locals.Count == 0) { return(false); } for (int i = 0; i < locals.Count; i++) { //dont look at yourself if (locals[i] == w_ThisEntity) { continue; } Factions factions = (Factions)w_FactionMapper.get(locals[i]); if (factions == null) { continue; } //is this local known to this entity if (factions.KnownFactions.ContainsKey(w_EntityFaction.OwnerFaction.Name)) { //should this entity be hostile towards this local? if (factions.KnownFactions[w_EntityFaction.OwnerFaction.Name].Value < 0) { Position pos = (Position)w_PositionMapper.get(w_ThisEntity); Position tPos = (Position)w_PositionMapper.get(locals[i]); if (Vector2.Distance(pos.Pos + pos.Offset, tPos.Pos + tPos.Offset) <= 200f) { //go hostile against it w_Target = locals[i]; Aggrivation aggro = (Aggrivation)w_AggroMapper.get(w_ThisEntity); aggro.Target = w_Target; return(true); } else { continue; } } } } return(false); }
/// <summary> /// has the entity collided /// </summary> /// <returns>returns true if it did</returns> private bool hasCollided() { MapCollidable collidable = (MapCollidable)w_ColidableMapper.get(w_ThisEntity); return(collidable.Collided); }
/// <summary> /// handle melee attacks /// </summary> /// <param name="attack">attack to handle</param> private void handleMelee(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.MeleeWeapon); 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 muscle = attAttr.Muscle.Value; int quickness = defAttr.Quickness.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.Melee.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 + muscle / 4) / (endurance / 10)) * (weapon.Lethality / armor.Mitigation)); int maxDmg = (int)((overhit + 1f) * ((atkSkill / 5 + muscle / 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); 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 (interactee != 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 * GameConfig.AwardDefs.MeleeMod) { UtilFactory.createSkillupAward(attack.Defender, attack.Attacker, SkillName.MELEE, 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 (muscle < endurance) { if (rand.NextDouble() <= ((double)(endurance - muscle) / (double)endurance) * GameConfig.AwardDefs.StatChance) { UtilFactory.createAttributeAward(attack.Defender, attack.Attacker, StatType.MUSCLE, 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 < muscle) { if (rand.NextDouble() <= ((double)(muscle - endurance) / (double)muscle) * GameConfig.AwardDefs.StatChance) { UtilFactory.createAttributeAward(attack.Attacker, attack.Defender, StatType.ENDURANCE, GameConfig.AwardDefs.StatMinimum); } } } } //remove attack ecs_instance.delete_entity(_CurrentEntity); }
protected override void process(Entity entity) { MeleeAction action = (MeleeAction)m_MeleeActionMapper.get(entity); Position position = (Position)m_PositionMapper.get(entity); SpatialPartition spatial = (SpatialPartition)m_SpatialMapper.get(m_Spatial); action.ElapsedTime += ecs_instance.ElapsedTime; //is it time for the melee action to die? if (action.ElapsedTime >= action.Lifetime) { ecs_instance.delete_entity(entity); return; } //retrieve all local entities //List<Entity> locals = spatial.QuadTree.retrieveContentsAtLocation(position.Pos); List <Entity> locals = spatial.QuadTree.findAllWithinRange(position.Pos, action.Range); //is the location good? if (locals != null) { //is there anyone here? if (locals.Count > 0) { for (int i = 0; i < locals.Count; i++) { //dont attempt to melee owner if (locals[i] == action.Owner) { continue; } if (action.HitByAction.Contains(locals[i])) { continue; } Life life = (Life)m_LifeMapper.get(locals[i]); //if no life, dont bother if (life == null) { continue; } //if not alive, dont bother if (!life.IsAlive) { continue; } //interaction available? Interactable interactions = (Interactable)m_InteractionMapper.get(locals[i]); if (interactions != null) { Position lPosition = (Position)m_PositionMapper.get(locals[i]); Position oPosition = (Position)m_PositionMapper.get(action.Owner); Vector2 lToO = (oPosition.Pos + oPosition.Offset) - (lPosition.Pos + lPosition.Offset); //local to owner Heading head = (Heading)m_HeadingMapper.get(entity); //get the weapon heading bool facing = (Vector2.Dot(head.getHeading(), lToO) < 0); //is the weapon facing the local? //if you're facing, are you within range? if (facing && (Vector2.Distance(lPosition.Pos + lPosition.Offset, position.Pos + position.Offset) <= action.Range)) { //does it support this interaction? if (interactions.SupportedInteractions.MELEE_ACTIONABLE && interactions.SupportedInteractions.ATTACKABLE) { Factions lfactions = (Factions)m_FactionMapper.get(locals[i]); Factions pfactions = (Factions)m_FactionMapper.get(action.Owner); //dont attack allies if (lfactions.OwnerFaction.FactionType == pfactions.OwnerFaction.FactionType) { continue; } //add to hit-list so we dont attack it again on swing follow-through action.HitByAction.Add(locals[i]); //create melee attack UtilFactory.createAttack(action.Owner, locals[i], AttackType.Melee); //destroy melee action //ecs_instance.delete_entity(entity); //return; } } } } } } //get info for rotation update Heading heading = (Heading)m_HeadingMapper.get(entity); Transform transform = (Transform)m_TransformMapper.get(entity); //rotate melee by degrees over the melee arc float rot = (((float)action.Animation.updateFrame(ecs_instance.ElapsedTime) / (float)action.Animation.Frames) * action.ArcDegrees) - (action.ArcDegrees / 2f); transform.Rotation = rot * (((float)Math.PI) / 180f) - VectorHelper.getAngle(new Vector2(1, 0), heading.getHeading()); //adjust the arc based on current position (i.e., move with the player) Position ownerPos = (Position)m_PositionMapper.get(action.Owner); Vector2 pos = ownerPos.Pos + new Vector2(16, 0);// +ownerPos.getOffset(); Vector2 dir = heading.getHeading(); dir.Normalize(); position.Pos = pos + dir * 10; }
/// <summary> /// perform all needed initialization /// </summary> /// <returns>whether initialization was a success or not</returns> private BehaviorReturnCode initialize() { Position position = (Position)w_PositionMapper.get(w_ThisEntity); w_Spatial = w_ECSInstance.tag_manager.get_entity_by_tag("SPATIAL"); SpatialPartition spatial = (SpatialPartition)w_SpatialMapper.get(w_Spatial); Vector2 pos = position.Pos; Vector2 dir = new Vector2((float)w_Random.NextDouble() * 2 - 1, (float)w_Random.NextDouble() * 2 - 1); dir.Normalize(); Heading heading = (Heading)w_HeadingMapper.get(w_ThisEntity); heading.setHeading(dir); w_LastNode = spatial.QuadTree.setContentAtLocation(w_ThisEntity, pos + new Vector2(16, 16)); w_Camera = w_ECSInstance.tag_manager.get_entity_by_tag("CAMERA"); w_EntityFaction = (Factions)w_FactionMapper.get(w_ThisEntity); return(BehaviorReturnCode.Success); }
private BehaviorReturnCode updateAnimation() { //grab components Sprite sprite = (Sprite)s_SpriteMapper.get(s_ThisEntity); Heading heading = (Heading)s_HeadingMapper.get(s_ThisEntity); //reset animation index sprite.Column = 0; //determine angle of heading float angle = VectorHelper.getAngle(new Vector2(1, 0), heading.getHeading()); //adjust spritesheet row based on angle if (angle >= 0.393f && angle < 1.178f) { sprite.Row = MOVE_UPRIGHT; } else if (angle >= 1.178f && angle < 1.963f) { sprite.Row = MOVE_UP; } else if (angle >= 1.963f && angle < 2.749f) { sprite.Row = MOVE_UPLEFT; } else if (angle >= 2.749f && angle < 3.534f) { sprite.Row = MOVE_LEFT; } else if (angle >= 3.534f && angle < 4.320f) { sprite.Row = MOVE_DOWNLEFT; } else if (angle >= 4.320f && angle < 5.105f) { sprite.Row = MOVE_DOWN; } else if (angle >= 5.105f && angle < 5.890f) { sprite.Row = MOVE_DOWNRIGHT; } else if (angle >= 5.890f || angle < .393f) { sprite.Row = MOVE_RIGHT; } //if you moved this cycle, update your animation frame accordingly, otherwise reset if (s_moved) { sprite.Column = s_Animation.updateFrame(s_EcsInstance.ElapsedTime); } else { s_Animation.reset(); } //reset movement flag s_moved = false; return(BehaviorReturnCode.Success); }
protected override void process(Entity entity) { //Damage damage = (Damage)_DamageMapper.get(entity); FloatingText text = (FloatingText)_FloatMapper.get(entity); if (text == null) { return; } else { //see if we should destroy this text.ElapsedTime += ecs_instance.ElapsedTime; if (text.ElapsedTime >= text.Lifetime) { ecs_instance.delete_entity(entity); return; } } Position position = (Position)_PositionMapper.get(entity);//damage.Target); if (position == null || text == null) { return; } ViewPort camera = (ViewPort)_ViewPortMapper.get(_Camera); Vector2 origin = camera.getOrigin(); Vector2 pos = position.Pos + new Vector2(0, -text.ElapsedTime / 7); //String dmg; //Color color = Color.Yellow; /* * if (damage.DamageAmount == 0) * { * dmg = "miss"; * color = Color.White; * } * else * dmg = "" + damage.DamageAmount; */ float fade = 1f; float half = (float)text.Lifetime / 2f; if (text.ElapsedTime > half) { fade = (1f - (text.ElapsedTime - half) / half); } //background _sprite_batch.DrawString(_Font, text.Text, pos - origin + new Vector2(1, 0), Color.Black * fade); _sprite_batch.DrawString(_Font, text.Text, pos - origin + new Vector2(-1, 0), Color.Black * fade); _sprite_batch.DrawString(_Font, text.Text, pos - origin + new Vector2(0, 1), Color.Black * fade); _sprite_batch.DrawString(_Font, text.Text, pos - origin + new Vector2(0, -1), Color.Black * fade); //foreground _sprite_batch.DrawString(_Font, text.Text, pos - origin, text.Color * fade); }