public static void ApplyDamage(DamageProperty prop, Unit source, GridCell target, int level) { if (prop.targetCasterOverride) { int damage = BattleCalculations.CalculateDamage(source, source, prop.damagePerLevel [level].min, prop.damagePerLevel [level].max, prop.element, prop.scaleFactor); source.Damage(damage, prop.element); } else if (target.currentUnit != null) { if (target.currentUnit == source) { if (prop.affectsCaster) { int damage = BattleCalculations.CalculateDamage(source, source, prop.damagePerLevel [level].min, prop.damagePerLevel [level].max, prop.element, prop.scaleFactor); source.Damage(damage, prop.element); } } else if (prop.affectedUnits.Contains(target.currentUnit.unitType)) { int damage = BattleCalculations.CalculateDamage(source, target.currentUnit, prop.damagePerLevel [level].min, prop.damagePerLevel [level].max, prop.element, prop.scaleFactor); target.currentUnit.Damage(damage, prop.element); } } }
public override void TakeDamage(DamageProperty WeaponPro, Unit Attacker) { base.TakeDamage(WeaponPro, Attacker); try { Camera.main.transform.Rotate(-5, 0, 0); screen_hit.Hit_Full = 1; } catch { } }
public SkillAttack(byte attackPoint, short targetCount, long magicPathId, long cubeMagicPathId, RangeProperty rangeProperty, List <SkillCondition> skillConditions, DamageProperty damageProperty) { AttackPoint = attackPoint; TargetCount = targetCount; MagicPathId = magicPathId; CubeMagicPathId = cubeMagicPathId; RangeProperty = rangeProperty; SkillConditions = skillConditions; DamageProperty = damageProperty; }
public virtual void TakeDamage(DamageProperty WeaponPro, Unit Attacker) { float Total = 0; //免疫伤害处理 States.DefenseLevel.APPower -= WeaponPro.APPower; if (States.DefenseLevel.APPower > 0) { return; } if (States.DefenseLevel.ToxinPower != 0) { WeaponPro.SlashPower = 0; } //伤害叠加 if (WeaponPro.KineticPower != 0) { Total += WeaponPro.KineticPower - States.DefenseLevel.KineticPower - States.DefenseLevel.KineticPower - States.DefenseLevel.ToxinPower; Total = Mathf.Clamp(Total, 0, Mathf.Infinity); } if (WeaponPro.ChemicalPower != 0) { Total += WeaponPro.ChemicalPower - States.DefenseLevel.ChemicalPower - States.DefenseLevel.ToxinPower; Total = Mathf.Clamp(Total, 0, Mathf.Infinity); } if (WeaponPro.ToxinPower != 0) { Total += WeaponPro.ToxinPower - States.DefenseLevel.ChemicalPower; Total = Mathf.Clamp(Total, 0, Mathf.Infinity); } if (WeaponPro.SlashPower != 0) { Total += WeaponPro.SlashPower - States.DefenseLevel.KineticPower; Total = Mathf.Clamp(Total, 0, Mathf.Infinity); } if (Attacker.tag == Tags.player) { NetworkInterface.Instance.HitFeedback(this, Total); } States.PerHP -= Total; if (ServerManager.Instance != null) { int id = ClientManager.Instance.GetNetworkIDByUnit(this); ServerManager.Instance.SynchronizingUnitStates(id, States); if (States.PerHP <= 0) { ServerManager.Instance.KillPlayerRequest(id); } } }
public void DamageRequest(Unit Attacker, DamageProperty property, Unit Victim) { MessageDamage damage = new MessageDamage(); //找施暴者 foreach (ClientsProperty p in ClientManager.Instance.clients.Values) { if (Attacker == p.unit) { damage.AttackerNetworkID = p.NetworkStates.NetworkID; } } foreach (ClientsProperty p in ClientManager.Instance.NetworkObjects.Values) { if (Attacker == p.unit) { damage.AttackerNetworkID = p.NetworkStates.NetworkID; } } //找受害人 foreach (ClientsProperty p in ClientManager.Instance.clients.Values) { if (Victim == p.unit) { damage.ViticmNetworkID = p.NetworkStates.NetworkID; } } foreach (ClientsProperty p in ClientManager.Instance.NetworkObjects.Values) { if (Victim == p.unit) { damage.ViticmNetworkID = p.NetworkStates.NetworkID; } } damage.WeaponPower = property; ClientManager.Instance.SendMessage(damage); }
private void CopyDamageProperty(DamageProperty prop) { eElement element = new eElement(); element = prop.element; eStat scaling = new eStat(); scaling = prop.scaleFactor; MinMaxValue[] values = new MinMaxValue[5]; for (int i = 0; i < 5; i++) { MinMaxValue val = new MinMaxValue(prop.damagePerLevel [i].min, prop.damagePerLevel [i].max); values [i] = val; } bool targetCaster = prop.targetCasterOverride; bool affectCaster = prop.affectsCaster; bool allies = prop.affectsAllyPlayers; bool allySummon = prop.affectsAllySummons; bool enemies = prop.affectsEnemyPlayers; bool enemySummon = prop.affectsAllySummons; DamageProperty newProp = new DamageProperty(); newProp.element = element; newProp.scaleFactor = scaling; newProp.damagePerLevel = values; newProp.targetCasterOverride = targetCaster; newProp.affectsCaster = affectCaster; newProp.affectsAllyPlayers = allies; newProp.affectsAllySummons = allySummon; newProp.affectsEnemyPlayers = enemies; newProp.affectsEnemySummons = enemySummon; ability.critDamageEffects.Add(newProp); }
void OnTriggerStay(Collider other) { if (gunType == WeaponType.LaserGun) { GameScene gameScene = GameApp.GetInstance().GetGameScene(); Player player = gameScene.GetPlayer(); Weapon w = player.GetWeapon(); if (w.GetWeaponType() == WeaponType.LaserGun) { LaserGun lg = w as LaserGun; if (lg.CouldMakeNextShoot()) { if (other.gameObject.layer == PhysicsLayer.ENEMY) { Enemy enemy = gameScene.GetEnemyByID(other.gameObject.name); if (enemy != null) { if (enemy.GetState() != Enemy.DEAD_STATE) { Object.Instantiate(laserHitObject, enemy.GetPosition(), Quaternion.identity); DamageProperty dp = new DamageProperty(); dp.hitForce = (dir + new Vector3(0f, 0.18f, 0f)) * hitForce; dp.damage = damage; enemy.OnHit(dp, gunType, false); } } } /* * else if (other.gameObject.layer == PhysicsLayer.WOODBOX) * { * WoodBoxScript ws = other.gameObject.GetComponent<WoodBoxScript>(); * ws.OnHit(damage); * }*/ } } } }
protected override List <SkillMetadata> Parse() { List <SkillMetadata> skillList = new(); foreach (PackFileEntry entry in Resources.XmlReader.Files) { // Parsing Skills if (entry.Name.StartsWith("skill")) { XmlDocument document = Resources.XmlReader.GetXmlDocument(entry); XmlNode ui = document.SelectSingleNode("/ms2/basic/ui"); XmlNode kinds = document.SelectSingleNode("/ms2/basic/kinds"); XmlNode stateAttr = document.SelectSingleNode("/ms2/basic/stateAttr"); XmlNodeList levels = document.SelectNodes("/ms2/level"); int skillId = int.Parse(Path.GetFileNameWithoutExtension(entry.Name)); string skillState = kinds.Attributes["state"]?.Value ?? ""; byte skillAttackType = byte.Parse(ui.Attributes["attackType"]?.Value ?? "0"); SkillType skillType = (SkillType)byte.Parse(kinds.Attributes["type"].Value); SkillSubType skillSubType = (SkillSubType)byte.Parse(kinds.Attributes["subType"]?.Value ?? "0"); byte skillElement = byte.Parse(kinds.Attributes["element"].Value); byte skillSuperArmor = byte.Parse(stateAttr.Attributes["superArmor"].Value); bool skillRecovery = int.Parse(kinds.Attributes["spRecoverySkill"]?.Value ?? "0") == 1; List <SkillLevel> skillLevels = new(); foreach (XmlNode level in levels) { // Getting all skills level string feature = level.Attributes["feature"]?.Value ?? ""; int levelValue = int.Parse(level.Attributes["value"].Value ?? "0"); // We prevent duplicates levels from older balances. if (skillLevels.Exists(x => x.Level == levelValue)) { continue; } List <SkillMotion> skillMotions = new(); foreach (XmlNode motionNode in level.SelectNodes("motion")) { string sequenceName = motionNode.SelectSingleNode("motionProperty")?.Attributes["sequenceName"].Value ?? ""; string motionEffect = motionNode.SelectSingleNode("motionProperty")?.Attributes["motionEffect"].Value ?? ""; List <SkillAttack> skillAttacks = new(); foreach (XmlNode attackNode in motionNode.SelectNodes("attack")) { // TODO: Parse other properties like: pause, arrow DamageProperty damageProperty = ParseDamageProperty(attackNode); RangeProperty rangeProperty = ParseRangeProperty(attackNode); byte attackPoint = byte.Parse(Regex.Match(attackNode.Attributes["point"]?.Value, @"\d").Value); short targetCount = short.Parse(attackNode.Attributes["targetCount"].Value); long magicPathId = long.Parse(attackNode.Attributes["magicPathID"]?.Value ?? "0"); long cubeMagicPathId = long.Parse(attackNode.Attributes["cubeMagicPathID"]?.Value ?? "0"); List <SkillCondition> skillConditions = new(); foreach (XmlNode conditionNode in attackNode.SelectNodes("conditionSkill")) { int conditionSkillId = int.Parse(conditionNode.Attributes["skillID"]?.Value ?? "0"); short conditionSkillLevel = short.Parse(conditionNode.Attributes["level"]?.Value ?? "0"); bool splash = conditionNode.Attributes["splash"]?.Value == "1"; byte target = byte.Parse(conditionNode.Attributes["skillTarget"].Value ?? "0"); byte owner = byte.Parse(conditionNode.Attributes["skillOwner"]?.Value ?? "0"); bool immediateActive = conditionNode.Attributes["immediateActive"]?.Value == "1"; short fireCount = short.Parse(conditionNode.Attributes["fireCount"].Value ?? "0"); int interval = int.Parse(conditionNode.Attributes["interval"].Value ?? "0"); skillConditions.Add(new(conditionSkillId, conditionSkillLevel, splash, target, owner, fireCount, interval, immediateActive)); } skillAttacks.Add(new(attackPoint, targetCount, magicPathId, cubeMagicPathId, rangeProperty, skillConditions, damageProperty)); } skillMotions.Add(new(sequenceName, motionEffect, skillAttacks)); } SkillUpgrade skillUpgrade = ParseSkillUpgrade(level); (int spirit, int stamina) = ParseConsume(level); skillLevels.Add(new(levelValue, spirit, stamina, feature, skillMotions, skillUpgrade)); } skillList.Add(new(skillId, skillLevels, skillState, skillAttackType, skillType, skillSubType, skillElement, skillSuperArmor, skillRecovery)); } // Parsing SubSkills if (entry.Name.StartsWith("table/job")) { XmlDocument document = Resources.XmlReader.GetXmlDocument(entry); XmlNodeList jobs = document.SelectNodes("/ms2/job"); foreach (XmlNode job in jobs) { // Grabs all the skills and them the jobCode. XmlNodeList skills = job.SelectNodes("skills/skill"); int jobCode = int.Parse(job.Attributes["code"].Value); foreach (XmlNode skill in skills) { int id = int.Parse(skill.Attributes["main"].Value); short maxLevel = short.Parse(skill.Attributes["maxLevel"]?.Value ?? "1"); skillList.Find(x => x.SkillId == id).Job = jobCode; skillList.Find(x => x.SkillId == id).MaxLevel = maxLevel; // If it has subSkill, add as well. if (skill.Attributes["sub"] == null) { continue; } int[] sub = skill.Attributes["sub"].Value.Split(",").Select(int.Parse).ToArray(); skillList.Find(x => x.SkillId == id).SubSkills = sub; foreach (int subSkillId in sub) { SkillMetadata subSkill = skillList.FirstOrDefault(x => x.SkillId == subSkillId); if (subSkill is null) { continue; } subSkill.Job = jobCode; } } XmlNodeList learnSkills = job.SelectNodes("learn/skill"); foreach (XmlNode learnSkill in learnSkills) { int id = int.Parse(learnSkill.Attributes["id"].Value); skillList.Find(x => x.SkillId == id).CurrentLevel = 1; } } } } // Parsing Additional Data foreach (PackFileEntry entry in Resources.XmlReader.Files) { if (!entry.Name.StartsWith("additionaleffect")) { continue; } XmlDocument document = Resources.XmlReader.GetXmlDocument(entry); XmlNodeList levelNodes = document.SelectNodes("/ms2/level"); int skillId = int.Parse(Path.GetFileNameWithoutExtension(entry.Name)); SkillMetadata skill = skillList.FirstOrDefault(x => x.SkillId == skillId); if (skill is null) { continue; } foreach (XmlNode levelNode in levelNodes) { int currentLevel = int.Parse(levelNode.SelectSingleNode("BasicProperty").Attributes["level"]?.Value ?? "0"); SkillLevel skillLevel = skill.SkillLevels.FirstOrDefault(x => x.Level == currentLevel); if (skillLevel is null) { continue; } skillLevel.SkillAdditionalData = ParseSkillData(levelNode); } } return(skillList); }
protected override void Start() { base.Start(); Damage = GetComponent <DamageProperty>(); }
void OnTriggerEnter(Collider other) { GameScene gameScene = GameApp.GetInstance().GetGameScene(); Player player = gameScene.GetPlayer(); /* * if (gunType == WeaponType.Sniper) * { * * Object.Instantiate(rConf.rocketExlposion, proTransform.position, Quaternion.identity); * Object.DestroyObject(gameObject); * * * if (other.gameObject.layer == PhysicsLayer.ENEMY) * { * Enemy enemy = gameScene.GetEnemyByID(other.gameObject.name); * DamageProperty dp = new DamageProperty(); * //dp.hitForce = (dir + new Vector3(0f, 0.18f, 0f)) * hitForce; * dp.damage = damage; * enemy.OnHit(dp, gunType, true); * } * * * } */ if (gunType == WeaponType.RocketLauncher || gunType == WeaponType.GrenadeRifle || gunType == WeaponType.Sniper) { GameObject.Instantiate(rConf.rpgFloor, new Vector3(proTransform.position.x, Constant.FLOORHEIGHT + 0.1f, proTransform.position.z), Quaternion.Euler(270, 0, 0)); Object.Instantiate(explodeObject, proTransform.position, Quaternion.identity); Object.DestroyObject(gameObject); player.LastHitPosition = proTransform.position; int oneShotKills = 0; foreach (Enemy enemy in gameScene.GetEnemies().Values) { if (enemy.GetState() == Enemy.DEAD_STATE) { continue; } float dis = (enemy.GetPosition() - proTransform.position).sqrMagnitude; float radiusSqr = explodeRadius * explodeRadius; if (dis < radiusSqr) { DamageProperty dp = new DamageProperty(); dp.hitForce = (dir + new Vector3(0f, 0.18f, 0f)) * hitForce; if (dis * 4 < radiusSqr) { dp.damage = damage * player.PowerBuff; enemy.OnHit(dp, gunType, true); } else { dp.damage = damage / 2 * player.PowerBuff; enemy.OnHit(dp, gunType, false); } } if (enemy.HP <= 0) { oneShotKills++; } } if (oneShotKills >= 4) { GameApp.GetInstance().GetGameState().Achievement.CheckAchievemnet_WeaponMaster(); } GameObject[] woodboxes = gameScene.GetWoodBoxes(); foreach (GameObject woodbox in woodboxes) { if (woodbox != null) { float dis = (woodbox.transform.position - proTransform.position).sqrMagnitude; float radiusSqr = explodeRadius * explodeRadius; if ((dis < radiusSqr)) { WoodBoxScript ws = woodbox.GetComponent <WoodBoxScript>(); ws.OnHit(damage * player.PowerBuff); } } } return; } else if (gunType == WeaponType.LaserGun) { if (other.gameObject.layer == PhysicsLayer.ENEMY) { Enemy enemy = gameScene.GetEnemyByID(other.gameObject.name); if (enemy != null) { if (enemy.GetState() != Enemy.DEAD_STATE) { //Object.Instantiate(laserHitObject, enemy.GetPosition(), Quaternion.identity); DamageProperty dp = new DamageProperty(); dp.hitForce = (dir + new Vector3(0f, 0.18f, 0f)) * hitForce; dp.damage = damage; enemy.OnHit(dp, gunType, false); } } } else if (other.gameObject.layer == PhysicsLayer.WOODBOX) { //Debug.Log("hit wood"); WoodBoxScript ws = other.gameObject.GetComponent <WoodBoxScript>(); ws.OnHit(damage); } //Object.Instantiate(laserHitObject, proTransform.position + dir * 2, Quaternion.identity); } else if (gunType == WeaponType.NurseSaliva) { if (other.gameObject.layer != PhysicsLayer.ENEMY) { Ray ray = new Ray(proTransform.position + Vector3.up * 1.0f, Vector3.down); RaycastHit hit; float floorY = Constant.FLOORHEIGHT; if (Physics.Raycast(ray, out hit, 100, 1 << PhysicsLayer.FLOOR)) { floorY = hit.point.y; } Object.Instantiate(smallExplodeObject, new Vector3(proTransform.position.x, floorY + 0.1f, proTransform.position.z), Quaternion.identity); GameObject salivaObj = Object.Instantiate(rConf.nurseSaliva, new Vector3(proTransform.position.x, floorY + 0.1f, proTransform.position.z), Quaternion.Euler(0, 0, 0)) as GameObject; salivaObj.transform.Rotate(270, 0, 0); Object.DestroyObject(gameObject); if ((player.GetTransform().position - proTransform.position).sqrMagnitude < explodeRadius * explodeRadius) { player.OnHit(damage); } } } }
void DrawDamageProperty(DamageProperty prop, int index, bool crit) { int propID = crit ? critTotal + total : total; EditorGUILayout.BeginVertical("box"); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); GUILayout.Space(5); DisplayElementLabel(prop.element); EditorGUILayout.LabelField(prop.damagePerLevel [showLevel - 1].min + " - " + prop.damagePerLevel [showLevel - 1].max, EditorStyles.boldLabel, GUILayout.MaxWidth(60)); EditorGUILayout.LabelField("at level " + showLevel, GUILayout.MinWidth(60)); DisplayScaleFactor(prop.scaleFactor); if (editEffectIndex == propID) { if (GUILayout.Button("Hide", EditorStyles.miniButtonLeft, GUILayout.Width(60))) { editEffectIndex = int.MaxValue; } } else { if (GUILayout.Button("Show", EditorStyles.miniButtonLeft, GUILayout.Width(60))) { editEffectIndex = propID; } } if (GUILayout.Button("Remove", EditorStyles.miniButtonRight, GUILayout.Width(60))) { if (!crit) { ability.damageEffects.RemoveAt(index); total--; } else { ability.critDamageEffects.RemoveAt(index); critTotal--; } return; } GUILayout.Space(5); EditorGUILayout.EndHorizontal(); GUILayout.Space(2); if (editEffectIndex == propID) { GUILayout.Space(4); EditorGUILayout.BeginHorizontal(); GUILayout.Space(4); EditorGUILayout.LabelField("Element:", GUILayout.Width(60)); prop.element = (eElement)EditorGUILayout.EnumPopup(prop.element, GUILayout.Width(80), GUILayout.Height(15)); GUILayout.Space(15); EditorGUILayout.LabelField("Scaling:", GUILayout.Width(60)); prop.scaleFactor = (eStat)EditorGUILayout.EnumPopup(prop.scaleFactor, GUILayout.Width(80), GUILayout.Height(15)); EditorGUILayout.EndHorizontal(); GUILayout.Space(2); for (int i = 0; i < 5; i++) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(4); EditorGUILayout.LabelField("Level " + (i + 1) + ":", GUILayout.Width(60)); GUILayout.Label("Min Damage:"); prop.damagePerLevel[i].min = EditorGUILayout.IntField(prop.damagePerLevel[i].min, GUILayout.Width(40)); GUILayout.Space(60); GUILayout.Label("Max Damage:"); prop.damagePerLevel[i].max = EditorGUILayout.IntField(prop.damagePerLevel[i].max, GUILayout.Width(40)); GUILayout.Space(60); EditorGUILayout.EndHorizontal(); } GUILayout.Space(5); } //Affected Units. DrawAffectedUnitsPanel(propID, ref prop.targetCasterOverride, ref prop.affectsCaster, ref prop.affectsAllyPlayers, ref prop.affectsAllySummons, ref prop.affectsEnemyPlayers, ref prop.affectsEnemySummons); EditorGUILayout.EndVertical(); }