public void TakeDamageInvoke(MechManager source, float damageTaken) { int damagedSections = 0; TotalCurrentHealth = 0; foreach (Section sec in sectionsAsList) { TotalCurrentHealth += sec.CurrentHealth; if (sec.CurrentHealthPercent < 0.333f) { damagedSections++; if (sec.IsCritical) { CriticallyDamaged = true; } } } if (damagedSections >= 3) { CriticallyDamaged = true; } OnDamageTaken(source, damageTaken); }
void Update() { weaponSystem.FindTargetInView(); if (weaponSystem.target != null) { if (lastTarget == null) { lastTarget = weaponSystem.target; lastTarget.outlineHandler.EnableOutlines(true); } else if (weaponSystem.target != lastTarget) { lastTarget.outlineHandler.EnableOutlines(false); lastTarget = weaponSystem.target; lastTarget.outlineHandler.EnableOutlines(true); } } else if (lastTarget != null) { lastTarget.outlineHandler.EnableOutlines(false); } GetInput(); Move(); MoveCamera(); }
private void BuildClassWeapon(WeaponItem wItem, MechManager mechManager, SectionManager sectionManager, int secIndex, int subIndex, int classIndex) { if (wItem == null) { return; } /* Create the Wep */ GameObject newWeapon = Object.Instantiate(wItem.prefab); newWeapon.transform.parent = sectionManager.GetSectionLinksByIndex(secIndex, classIndex)[subIndex]; newWeapon.transform.localPosition = Vector3.zero; newWeapon.transform.localEulerAngles = Vector3.zero; /* Add the weapons to the MechManager on the mech encapsulating object */ mechManager.GetWeaponObjByIndex(secIndex).Add(newWeapon); /* Add the ref to the parent section to the weapon's script */ newWeapon.GetComponent <WeaponExecutable>().sectionParent = sectionManager.GetSectionByIndex(secIndex); newWeapon.GetComponent <WeaponExecutable>().mechManager = mechManager; // Move into modify??? /* Create an executable for the weapon and add it to MechManager ref */ mechManager.GetExecutableByIndex(secIndex).Add(newWeapon.GetComponent <WeaponExecutable>()); }
// Use this for initialization void Start() { manager = GameObject.Find("Manager").GetComponent <MechManager> (); /*foreach (string s in mountNames) { * * GameObject x = Instantiate(mechItem); * x.transform.SetParent(gameObject.transform); * x.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); * x.transform.position = Vector3.zero; * x.transform.rotation = gameObject.transform.rotation; * Text text = (x.GetComponentInChildren<Text>()); * * * * items.Add(x); * text.text = s; * * * }*/ gameObject.transform.localEulerAngles = new Vector3(0, 20, 0); gameObject.transform.localPosition = new Vector3(179, -154, -1548); //new Vector3 (179, -154, -1548); }
protected override void SectionTookDamage(MechManager source, float damageTaken) { base.SectionTookDamage(source, damageTaken); if (!alerted) { alerted = true; } }
private void Awake() { manager = GetComponentInParent <MechManager>(); slots = GetComponentsInChildren <Slot>().ToList(); foreach (var slot in slots) { slot.container = this; } }
new void Start() { base.Start(); navAgent = GetComponent <NavMeshAgent>(); playerMech = LevelManager._instance.playerMechManager; navAgent.speed = 3; navAgent.angularSpeed = 180; }
public bool CheckTargetInView(MechManager targetMech, float viewAngle = 50, float maxDist = 100) { var dist = Vector3.Distance(transform.position, targetMech.transform.position); var angleBetween = Vector3.Angle(mechManager.sectionManager.torsoRotAxis.transform.forward, (targetMech.transform.position - transform.position)); bool ret = (angleBetween < viewAngle && dist < maxDist); if (ret) { target = targetMech; } return(ret); }
void Start() { manager = FindObjectOfType <MechManager>(); manager.AddMech(this.GetComponent <Mech>()); foreach (Module m in modules) { if (m == null) { continue; } Debug.Log("Module " + m + " and I am " + this); m.SetMech(this); } }
public override void Initialize(MechManager source, WeaponItem refItem, Transform target, Vector3 firingSolution, Vector3 spread) { this.target = target; mySource = source; damage = refItem.damage; speed = refItem.bulletSpeed; turnMinMax = refItem.turnMinMax; offsetMinMax = refItem.offsetMinMax; lifeTimer = refItem.bulletLife; turnSpeed = turnMinMax.x; randomOffset = offsetMinMax.x; }
public void TakeDamage(float damage, MechManager source) { if (IsDestroyed) { return; } float totalDamage = 0; if (CurrentArmor > 0) { totalDamage += damage * Mathf.Pow(.8f, (CurrentArmor / 100)); } else { totalDamage += damage; } float overflow = totalDamage - CurrentShield; // Damage breaks through shield if (overflow > 0) { CurrentHealth -= overflow; CurrentShield = 0; } // Damage doesnt break through shield else { CurrentShield -= totalDamage; } if (CurrentHealth <= 0) { if (!IsDestroyed) { IsDestroyed = true; ExecuteDestroy(); } } lastDamageTime = Time.time; CurrentHealthPercent = CurrentHealth / MaxHealth; OnDamageTaken(source, damage); }
public void AddMechToLists(MechManager mech) { switch (mech.mechFaction) { case Faction.Player: playerMechs.Add(mech); break; case Faction.Hostile: hostileMechs.Add(mech); break; case Faction.Neutral: neutralMechs.Add(mech); break; } }
public virtual void Initialize(MechManager source, WeaponItem refItem, Transform target, Vector3 firingSolution, Vector3 spread) { mySource = source; damage = refItem.damage; if (firingSolution != Vector3.zero) { transform.LookAt(firingSolution); } transform.rotation *= Quaternion.Euler(spread); GetComponent <Rigidbody>().velocity = transform.forward * refItem.bulletSpeed; Destroy(gameObject, refItem.bulletLife); }
public bool RegisterHit(float damage, MechManager source) { if (weapon != null) { weapon.sectionParent.TakeDamage(damage, source); return(true); } else if (section != null) { section.TakeDamage(damage, source); return(true); } return(false); }
void Awake() { world = new World(); inputManager = new InputManager(world); turnManager = new TurnManager(); mechManager = new MechManager(); networkManager = new NetworkManager(); OnUpdate += () => { if (Input.GetKeyDown(KeyCode.O)) { mechManager.GenerateDebugMechs(); } }; }
void Start() { bullet = weaponItemRef.bullet; refFireType = weaponItemRef.fireType; damage = weaponItemRef.damage; ammoMax = weaponItemRef.maxAmmo; ammoCurr = ammoMax; secBetweenFire = weaponItemRef.secBetweenFire; reloadTime = weaponItemRef.reloadTime; volleyCount = weaponItemRef.volleyCount; volleyDelay = weaponItemRef.volleyDelay; bulletSpread = weaponItemRef.bulletSpread; bloomInc = weaponItemRef.bloomIncrement; bloomDec = weaponItemRef.bloomDecrement; needsAnimationEvent = weaponItemRef.needsAnimationEvent; if (needsAnimationEvent) { animTriggers = GetComponentInChildren <AnimationTriggers>(); animTriggers.FireTrigger += AnimFireTrigger; animTriggers.FireReset += AnimFireReset; } if (sectionParent == null) { sectionParent = GetComponentInParent <Section>(); } if (mechManager == null) { mechManager = transform.root.GetComponent <MechManager>(); } bloomCurr = 0; //weaponGroup = (int)weaponItemRef.AmmoType; }
// Start is called before the first frame update void Start() { mechManager = GetComponent <MechManager>(); mechController = GetComponent <MechController>(); weaponGroups.Add(new WeaponGroup()); weaponGroups.Add(new WeaponGroup()); weaponGroups.Add(new WeaponGroup()); for (int secIndex = (int)SectionIndex.leftArm; secIndex < (int)SectionIndex.rightShoulder; secIndex++) { weaponExecutables.AddRange(mechManager.GetExecutableByIndex(secIndex)); } for (int i = 0; i < weaponExecutables.Count; i++) { weaponExecutables[i].refSystem = this; weaponGroups[(int)weaponExecutables[i].weaponItemRef.weaponClass].mappedWeapons.Add(weaponExecutables[i]); } }
bool FindTarget() { if (lastCombatTarget != null) { weaponSystem.CheckTargetInView(lastCombatTarget); } else { lastCombatTarget = weaponSystem.FindTargetInView(60, weaponSystem.optimalRanges.z); } if (lastCombatTarget != null) { lastKnownPosition = Vector3.zero; alerted = true; Alert(); } return(lastCombatTarget != null); }
/* Camera from this mech */ public MechManager FindTargetInView(float viewAngle = 50, float maxDist = 100) { var hostiles = LevelManager._instance.GetAllEntitiesInRange(gameObject, maxDist, mechManager.mechFaction); target = null; targetCenter = null; /* If hostile in view, then get the closest out of remaining */ float smallestAngle = 360; GameObject closestHostile = null; foreach (GameObject hostile in hostiles) { if (!hostile.activeInHierarchy || hostile.GetComponent <MechManager>().totallyDestroyed) { continue; } //var dist = Vector3.Distance(transform.position, hostile.transform.position); var angleBetween = Vector3.Angle(mechManager.sectionManager.torsoRotAxis.transform.forward, (hostile.transform.position - transform.position)); if (angleBetween < viewAngle && angleBetween < smallestAngle) { closestHostile = hostile; smallestAngle = angleBetween; } } if (closestHostile != null) { target = closestHostile.GetComponent <MechManager>(); targetCenter = target.GetTargetCenter(); } return(target); }
void InitializeLevel() { placeHolders = FindObjectsOfType <LevelMechPlaceholder>(); MechBuilder builder = new MechBuilder(); foreach (LevelMechPlaceholder mech in placeHolders) { mech.InitializeMech(builder); } levelMechSpawner = GetComponent <LevelMechSpawner>(); levelMechSpawner.levelManager = this; playerMechManager = SpawnPlayer(); for (int index = 0; index < levelObjectives.Count; index++) { levelObjectives[index].player = playerMechManager; if (index == 0) { InitializeObjective(levelObjectives[0]); } } }
public void Initialize() { mechManager = GetComponent <MechManager>(); sectionManager = GetComponent <SectionManager>(); weaponSystem = GetComponent <WeaponSystem>(); }
// Update is called once per frame void Update() { if (LevelManager._instance.playerMechManager.weaponSystem.target == null) { reticle.gameObject.SetActive(false); } else { //{ MechManager mechTarget = LevelManager._instance.playerMechManager.weaponSystem.target; reticle.gameObject.SetActive(true); // Vector2 space = Camera.main.WorldToScreenPoint(mechTarget.weaponSystem.targetCenter.position); // reticle.transform.position = space; // if (Vector3.Dot((mechTarget.transform.position - transform.position), transform.forward) < 0) // { // if (pos.x < Screen.width / 2) // { // pos.x = maxX; // } // else // pos.x = minX; // } //} //else //{ // reticle.enabled = false; //} var minX = reticle.GetPixelAdjustedRect().width / 2; var maxX = Screen.width - minX; var minY = reticle.GetPixelAdjustedRect().height / 2; var maxY = Screen.height - minY; Vector2 pos = Camera.main.WorldToScreenPoint(mechTarget.GetTargetCenter().position); if (Vector3.Dot((mechTarget.GetTargetCenter().position - reticle.transform.position), reticle.transform.forward) < 0) { reticle.gameObject.SetActive(false); if (pos.x < Screen.width / 2) { pos.x = maxX; } else { pos.x = minX; } } pos.x = Mathf.Clamp(pos.x, minX, maxX); pos.y = Mathf.Clamp(pos.y, minY, maxY); reticle.transform.position = pos; //distanceText.text = Mathf.Round(Vector3.Distance(transform.position, target.position)) + "m"; } }
public void SpawnFromLevelMech(int objectiveIndex) { MechBuilder builder = new MechBuilder(); foreach (LevelMech mech in levelMechs) { if (mech.onObjective != objectiveIndex) { continue; } MechManager newMech = builder.BuildFromMechObj(mech.pattern.mech, Vector3.zero, Quaternion.identity, true, false, mech.faction, mech.behaviorType, mech.aiLevel).GetComponent <MechManager>(); levelManager.AddMechToLists(newMech); var currObjective = levelManager.levelObjectives[objectiveIndex]; switch (mech.mechDirective) { case LevelMechDirective.Patrol: if (mech.route.Length > 0) { newMech.transform.position = mech.route[0].position; newMech.GetComponent <AIController>().patrolRoute = mech.route; } break; case LevelMechDirective.Target: newMech.transform.position = mech.spawnLocations[0].position; newMech.transform.rotation = mech.spawnLocations[0].rotation; if (mech.faction == Faction.Hostile) { if (currObjective.thisObjectiveType == ObjectiveType.DefendDestroy || currObjective.thisObjectiveType == ObjectiveType.DefendTime || currObjective.thisObjectiveType == ObjectiveType.Escort) { newMech.GetComponent <AIController>().destroyTarget = currObjective.defendMechs[0]; } if (currObjective.thisObjectiveType == ObjectiveType.DefendLocation) { newMech.GetComponent <AIController>().targetLocation = currObjective.location.transform; } } else if (mech.faction == Faction.Player) { if (currObjective.thisObjectiveType == ObjectiveType.Target || currObjective.thisObjectiveType == ObjectiveType.DefendDestroy) { newMech.GetComponent <AIController>().destroyTarget = currObjective.targetMechs[0]; } } break; case LevelMechDirective.Defend: newMech.transform.position = mech.spawnLocations[0].position; newMech.transform.rotation = mech.spawnLocations[0].rotation; if (mech.faction == Faction.Hostile) { if (currObjective.thisObjectiveType == ObjectiveType.Target || currObjective.thisObjectiveType == ObjectiveType.DefendDestroy) { newMech.GetComponent <AIController>().destroyTarget = currObjective.targetMechs[0]; } } else if (mech.faction == Faction.Player) { if (currObjective.thisObjectiveType == ObjectiveType.DefendDestroy || currObjective.thisObjectiveType == ObjectiveType.DefendTime || currObjective.thisObjectiveType == ObjectiveType.Escort) { newMech.GetComponent <AIController>().defendTarget = currObjective.defendMechs[0]; } if (currObjective.thisObjectiveType == ObjectiveType.DefendLocation) { // TODO newMech.GetComponent <AIController>().defendLocation = currObjective.location.transform; } } break; case LevelMechDirective.None: newMech.transform.position = mech.spawnLocations[0].position; newMech.transform.rotation = mech.spawnLocations[0].rotation; break; } } }
public void InitializeMech(MechBuilder builder) { initializedMechManager = builder.BuildFromMechObj(basePattern.mech, transform.position, transform.rotation, true, false, faction, behaviorType, aiLevel).GetComponent <MechManager>(); initializedMechManager.gameObject.SetActive(false); }
protected override void SectionTookDamage(MechManager source, float damageTaken) { mechManager.controllerHUD.GotHit(damageTaken); }
// Use this for initialization void Start() { manager = GameObject.Find ("Manager").GetComponent<MechManager> (); /*foreach (string s in mountNames) { GameObject x = Instantiate(mechItem); x.transform.SetParent(gameObject.transform); x.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); x.transform.position = Vector3.zero; x.transform.rotation = gameObject.transform.rotation; Text text = (x.GetComponentInChildren<Text>()); items.Add(x); text.text = s; }*/ gameObject.transform.localEulerAngles = new Vector3 (0, 20, 0); gameObject.transform.localPosition = new Vector3 (179, -154, -1548); //new Vector3 (179, -154, -1548); }
protected virtual void SectionTookDamage(MechManager source, float damageTaken) { BecomeAlerted(source.transform.position); }