public void AttachComponent(ShipComponent component) { if (component.GetShipComponentType() == ShipComponentType.CONE) { cone = (Cone)component; component.PlaceComponent(conePosition); } else if (component.GetShipComponentType() == ShipComponentType.ENGINE) { engine = (Engine)component; component.PlaceComponent(enginePosition); } else if (component.GetShipComponentType() == ShipComponentType.FUEL) { fuel = (Fuel)component; component.PlaceComponent(fuelPosition); } else if (component.GetShipComponentType() == ShipComponentType.WING) { wing = (Wing)component; component.PlaceComponent(wingPosition); } if (cone != null && engine != null && fuel != null && wing != null) { SceneManager.LoadScene("WinScene"); } }
override public void HandleEvent(string signal, object[] args) { switch (signal) { case "SpawnEntity": SpawnEntity(args[0] as ConcreteEntity); break; case "OnActiveShipChanged": ShipComponent sc = GetComponent <ShipController>().GetShipComponent(Emitter.ActiveShip()); selectorComponent.transform.SetParent(sc.transform); selectorComponent.transform.localEulerAngles = new Vector3(0, 0, 0); buildIndicatorComponent.transform.SetParent(sc.transform); buildIndicatorComponent.transform.localEulerAngles = new Vector3(0, 0, 90 * (int)buildIndicatorComponent.Emitter.Facing); GameObject.Find("Main Camera").transform.SetParent(sc.transform); GameObject.Find("Main Camera").transform.localEulerAngles = new Vector3(0, 0, 0); GameObject.Find("Main Camera").GetComponent <CameraController>().Center(); GameObject.Find("Overlay").transform.SetParent(sc.transform); GameObject.Find("Overlay").transform.localEulerAngles = new Vector3(0, 0, 0); GameObject.Find("Overlay").transform.localPosition = new Vector3(0, 0, 0); break; case "SpawnSelectionEntity": EntityComponent <ConcreteEntity> c = SpawnEntity(args[0] as ConcreteEntity); selectorComponent = c; break; } }
public override IEnumerator Fire(ShipComponent targetComp, Action OnActivationComplete) { //if (targetComp) { targetTrans = targetComp.transform; shootPoint.LookAt(targetTrans); Projectile_Missile missileClone = Instantiate(missilePrefab, shootPoint.position, shootPoint.rotation) as Projectile_Missile; bool missileCollided = false; missileClone.OnCollision += (GameObject other) => { if ((targetComp.ParentShip.ShieldStrength > 0.0f && other.layer == TagsAndLayers.ShipShieldLayer && other.GetComponentInParent<TurnBasedUnit>() == targetComp.ParentShip) || (other.layer == TagsAndLayers.ComponentsLayer && other.GetComponent<ShipComponent>() == targetComp)) { missileCollided = true; Instantiate(explosionPrefab, missileClone.transform.position, Quaternion.identity); Destroy(missileClone.gameObject); } }; while (!missileCollided && targetComp.ParentShip && targetComp.ParentShip.HullHP > 0.0f) { //Debug.Log("targetship hp " + targetComp.ParentShip.HullHP); yield return null; } yield return StartCoroutine(DoDamage(targetComp)); OnActivationComplete(); } }
public void DeleteFromItem(Item item) { ShipComponent component = item.transform.GetChild(0).GetComponent <ShipComponent>(); switch (item.itemclass) { case "ShieldGenerator": ship.maxshield -= component.value; ship.shieldregen -= component.supportvalue; ship.shieldregencost -= component.energyCost; break; case "Engine": ship.maxspeed -= component.value; ship.acceleration -= component.floatValue; break; case "Reactor": ship.maxenergy -= component.value; ship.enegyregen -= component.supportvalue; break; default: break; } Destroy(component.gameObject); }
public override void OnHp0() { if (AirShip.count == 7)//第一次弹药库损毁 { AirShip.count++; } Collider[] colliders = Physics.OverlapSphere(transform.position, 2); foreach (Collider collider in colliders) { if (collider.gameObject == this.gameObject) { continue; } ShipComponent sp = collider.gameObject.GetComponent <ShipComponent>(); if (sp != null) { sp.Damage(30); } } GameObject effect = Instantiate(explosionEffectPrefab, transform.position, transform.rotation); Destroy(effect, 1); Destroy(fireEffect); Destroy(gameObject); }
void Update() { ShipComponent activeShipComponent = GetComponent <ShipController>().GetShipComponent(verse.ActiveShip()); Vector3 localPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) - activeShipComponent.transform.position; localPos.z = 0; Vector3 rotatedPos = Quaternion.AngleAxis(-activeShipComponent.transform.localEulerAngles.z, Vector3.forward) * localPos; Coordinate coord = new Coordinate( rotatedPos ); verse.buildIndicatorEntity.Position = coord.ToVector(); if (Input.GetKeyDown(KeyCode.R)) { verse.buildIndicatorEntity.Rotate(); } if (verse.verseMode == Verse.VerseMode.Build) { if (Input.GetButtonDown("Fire1")) { Part part = verse.registry.partRegistry.Get(verse.modeArgs[0] as string); part.Facing = verse.buildIndicatorEntity.Facing; activeShipComponent.Emitter.AddPart(part, coord); } } if (Input.GetButtonDown("Fire3")) { verse.Select(coord); } }
Vector2 computeCenterOfMass() { int massTotal = 0; Vector2 weightedMass = new Vector2(0, 0); foreach (GameObject obj in componentArray) { if (obj != null) { ShipComponent shipComponent = obj.GetComponent("ShipComponent") as ShipComponent; massTotal += shipComponent._mass; weightedMass.x += (obj.transform.position.x * shipComponent._mass); weightedMass.y += (obj.transform.position.y * shipComponent._mass); } } weightedMass.x /= massTotal; weightedMass.y /= massTotal; totalMass = massTotal; //Debug.Log ("CenterofMass: " + weightedMass); return(weightedMass); }
void Interact() { Collider2D hitComponent = Physics2D.OverlapCircle(transform.position, interactRadius, shipComponentsMasks); if (hitComponent == null) { return; } ShipComponent shipComponent = hitComponent.GetComponent <ShipComponent>(); if (shipComponent == null) { Debug.LogWarning($"Player interacted with object {hitComponent.name} but it did not have a ShipComponent attached to it."); return; } shipComponent.Interact(); BreakableComponent breakable = shipComponent.GetComponent <BreakableComponent>(); if (breakable) { progressBar.gameObject.SetActive(true); } focus = shipComponent; }
public bool ComponentExists(ShipComponent comp) { if(componentList==null) { return false; } return componentList.Any(entry => entry.component == comp); }
public override void ApplyUpgrade (ShipComponent comp) { Wings w = comp.GetComponent (typeName) as Wings; if(!w) return; w.colSelfMult = 1-colSelfMult; w.colVictimMult = 1+colVictimMult; }
IEnumerator UpdateCooldownUI(ShipComponent component, Image image) { while (image != null) { image.fillAmount = component.cooldownRemainingInPercent; yield return(null); } }
void Add(ShipComponent sc) { if (!hackables.Contains(sc)) { hackables.Add(sc); totalComponentCount++; } }
void Start() { Physics2D.queriesHitTriggers = true; rb = GetComponent <Rigidbody2D> (); coll = GetComponent <Collider2D> (); main = GetComponent <ShipComponent> (); lightning = GameObject.Find("LineManager").GetComponent <Lightning> (); contactCondition = new ConditionManager(); }
public override void ApplyUpgrade (ShipComponent comp) { Engine e = comp.GetComponent (typeName) as Engine; if(!e) return; e.maxSpeed *= 1+maxMult; e.thrustMult *= 1+accMult; }
public override void ApplyUpgrade (ShipComponent comp) { Hull h = comp.GetComponent (typeName) as Hull; if(!h) return; h.maxHealth *= 1+healthMult; h.maxCapacity *= 1+capacityMult; }
/// <summary> /// Get the Renderer for the ship part returns null if doesnt exist /// </summary> /// <param name="renderer">the reference to the renderer</param> /// <param name="rendererName">the renderer's name</param> public void GetRenderer(ref ShipComponent renderer, string rendererName) { renderer = null; if (shipComponents.ContainsKey(rendererName)) { renderer = shipComponents[rendererName]; } }
public void AddEntry(int ID, ShipComponent component) { if(componentList == null) { componentList = new List<ComponentTableEntry>(); } component.ID = ID; componentList.Add((new ComponentTableEntry(ID, component))); }
void ApplyUpgrades(ShipComponent c) { foreach (Upgrade u in upgrades) { if (c.GetComponent(u.typeName) && u.bought) { u.ApplyUpgrade(c); } } }
public void WireUp(ShipComponent component, ShipComponentManager realShip) { var obj = Instantiate(component.prefab, pedestal); cost.text = component.cost.ToString(); partName.text = component.name; this.component = component; this.realShip = realShip; CookieTotal_ValueChanged(); buyText.gameObject.SetActive(false); }
public bool CanEquip(ShipComponent component) { if (!components.ContainsKey(component.type)) { return(true); } else { return(components[component.type].transform.childCount != component.prefab.transform.childCount); } }
/// <summary> /// Get the ship component /// </summary> /// <param>return the ship component</param> public ShipComponent GetShipComponent(string partName) { ShipComponent part = null; if (shipComponents.ContainsKey(partName)) { part = shipComponents[partName]; } return(part); }
public bool equals(ShipComponent other) { if (this.index_Row == other.index_Row && this.index_Column == other.index_Column) { return(true); } else { return(false); } }
public ShipComponentConstructor(ShipComponent sc) { gridLocation = Vec2Encode(sc.attached.gridLocation); gridRotation = sc.attached.gridRotation; health = sc.type.health; spawnIndex = sc.type.spawnIndex; position = Vec3Encode(sc.transform.position); scale = Vec3Encode(sc.transform.localScale); rotation = sc.transform.eulerAngles.z; }
public bool IsComponentCompatible(int slot, ShipComponent shipComponent) { if (shipComponentSlots.Count > slot) { if (shipComponent == null || shipComponent.GetComponentType() == shipComponentSlots[slot].componentType) { return true; } } return false; }
public void AddShipComponent(ShipComponent component) { if (components.ContainsKey(component.type)) { Destroy(components[component.type]); components.Remove(component.type); } var item = Instantiate(component.prefab, container); components.Add(component.type, item); }
public override void ApplyUpgrade(ShipComponent comp) { Wings w = comp.GetComponent(typeName) as Wings; if (!w) { return; } w.colSelfMult = 1 - colSelfMult; w.colVictimMult = 1 + colVictimMult; }
public override void ApplyUpgrade(ShipComponent comp) { Hull h = comp.GetComponent(typeName) as Hull; if (!h) { return; } h.maxHealth *= 1 + healthMult; h.maxCapacity *= 1 + capacityMult; }
public override void ApplyUpgrade(ShipComponent comp) { Engine e = comp.GetComponent(typeName) as Engine; if (!e) { return; } e.maxSpeed *= 1 + maxMult; e.thrustMult *= 1 + accMult; }
/// <summary> /// Updates each ship component and checks if player is close enough to interact with it /// </summary> /// <param name="component">Ship Object</param> /// <param name="gameTime">GameTime variable</param> private void UpdateShipComponent(ShipComponent component, GameTime gameTime) { component.Update(gameTime); Vector2 compPos = component.GetPosition(); float distance = Vector2.Distance(compPos, _player.GetPosition()); if (distance <= _player.interactRad) { _player.SetFocus(component); } }
public static int GetID(ShipComponent component) { #if FULL_DEBUG int compID; if(!comp_id_table.TryGetValue(component, out compID)) { Debug.LogError("Component " + component.componentName + " not found"); } return compID; #else return comp_id_table[component]; #endif }
protected override void Run(ETModel.Session session, M2C_CreateShips message) { ShipComponent unitComponent = ETModel.Game.Scene.GetComponent <ShipComponent>(); foreach (ShipInfo unitInfo in message.Ships) { if (unitComponent.Get(unitInfo.ShipId) != null) { continue; } Ship ship = ShipFactory.Create(unitInfo.ShipId); ship.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); } }
protected virtual bool checkAbility(ShipComponent component, string buttonName) { switch (component.activationMoment) { case ShipComponent.ActivationMoment.BUTTON_DOWN: return(Input.GetButtonDown(buttonName)); case ShipComponent.ActivationMoment.BUTTON_HELD: return(Input.GetButton(buttonName)); case ShipComponent.ActivationMoment.BUTTON_UP: return(Input.GetButtonUp(buttonName)); } throw new UnityException("Ship " + name + " has a component (" + component.name + ") that has an activation moment (" + component.activationMoment + ") that is not in the list!"); }
void CreateComponentItem(Transform root, ShipComponent component) { GameObject g = Instantiate(_componentItem, root); g.transform.Find("icon").GetComponent <Image>().sprite = component.icon; g.transform.Find("icon").GetComponent <Image>().color = component.ColorByRarity(); g.transform.Find("borders").GetComponent <Image>().color = component.ColorByRarity(); g.transform.GetComponent <GenericTooltipHandler>().Initialize( () => TooltipManager.getInstance.OpenTooltip(component.name + "\n" + component.GetSummary(), Input.mousePosition), null, null, null, () => TooltipManager.getInstance.CloseTooltip()); }
/// <summary> /// this start method is private, it initializes the all ships parts renderers, pariticle systems /// then calls the Initialize method, any ship code should go in Initialize instead /// </summary> private void Start() { // get sprite renderer and transform component from the all parts of the ship foreach (Transform part in transform) { // skip to next loop if the part render is already present in this collection if (shipComponents.ContainsKey(part.name)) { break; } if (part.name == "weapon") { ShipComponent comp = new ShipComponent { ComponentObject = part.gameObject, ComponentTransform = part, ComponentRenderer = part.GetComponent <SpriteRenderer>() }; shipComponents.Add("weapon", comp); } else if (part.name == "hull") { ShipComponent comp = new ShipComponent { ComponentObject = part.gameObject, ComponentTransform = part, ComponentRenderer = part.GetComponent <SpriteRenderer>() }; shipComponents.Add("hull", comp); } else if (part.name == "propulsion") { ShipComponent comp = new ShipComponent { ComponentObject = part.gameObject, ComponentTransform = part, ComponentRenderer = part.GetComponent <SpriteRenderer>() }; shipComponents.Add("propulsion", comp); } } Initialize(); }
public override IEnumerator Fire(ShipComponent targetComp, System.Action OnActivationComplete) { if (targetComp && targetComp.CompHP > 0.0f) { #if FULL_DEBUG //Debug.Log("Firing lasers"); #endif targetTrans = targetComp.transform; //length = Mathf.RoundToInt(Vector3.Distance(targetTrans.position, shootPoint.position)); bool beamHitsShields = targetComp.ParentShip.ShieldStrength > 0.0f; yield return StartCoroutine(DoDamage(targetComp)); yield return StartCoroutine(CreateBeamEffectForDuration(beamHitsShields, targetComp)); } OnActivationComplete(); }
public override GameObject Load() { GameObject obj = GameManager.singleton.SpawnNew(spawnIndex); obj.transform.position = Vec3Parse(position); obj.transform.localScale = Vec3Parse(scale); obj.transform.rotation = Quaternion.Euler(new Vector3(0, 0, rotation)); ShipComponent sc = obj.GetComponent <ShipComponent> (); sc.attached.gridLocation = Vec2Parse(gridLocation); sc.attached.gridRotation = gridRotation; sc.type.health = health; return(obj); }
public void AddComponent(int slotIndex, ShipComponent component ) { //if(componentTable == null) //{ // Debug.Log("null table"); //} //if(component == null) //{ // Debug.Log("null component"); //} //if(hull.SlotTable == null) //{ // Debug.Log("slot table null"); //} //Debug.Log("Adding comp: index: " + slotIndex + "slot: " + hull.SlotTable[slotIndex].index); componentTable.Add(hull.SlotTable[slotIndex], component); }
public override IEnumerator Fire(ShipComponent targetComp, Action OnActivationComplete) { //if(targetComp && targetComp.CompHP > 0.0f) { #if FULL_DEBUG //Debug.Log("Firing Railgun"); #endif targetTrans = targetComp.transform; shootPoint.LookAt(targetTrans); //for laser style railgun //yield return StartCoroutine(CreateRailEffect()); //for projectile railgun Projectile_Missile bulletClone = (Projectile_Missile)Instantiate(projectilePrefab, shootPoint.position, shootPoint.rotation); bulletClone.rigidbody.velocity = shootPoint.forward * projectileSpeed; //float distanceToTarget = Vector3.Distance(targetTrans.position, shootPoint.position); //float timeToTarget = distanceToTarget / projectileSpeed; ////muzzle flash bool bulletCollided = false; bulletClone.OnCollision += (GameObject other) => { if ((targetComp.ParentShip.ShieldStrength > 0.0f && other.layer == TagsAndLayers.ShipShieldLayer && other.GetComponentInParent<TurnBasedUnit>() == targetComp.ParentShip) || (other.layer == TagsAndLayers.ComponentsLayer && other.GetComponent<ShipComponent>() == targetComp)) { bulletCollided = true; Instantiate(explosionPrefab, bulletClone.transform.position, Quaternion.identity); Destroy(bulletClone.gameObject); } }; //float currentTimer = while (!bulletCollided) { yield return null; } Debug.Log("Weapon doing damage"); yield return StartCoroutine(DoDamage(targetComp)); } Debug.Log("Weapon activation complete"); OnActivationComplete(); }
private void WireUp(int idx, ShipComponent component) { //var obj = Instantiate(component.prefab, partStages[idx]); //F**k this noise, can't get it to center correctly //foreach (var collider in obj.GetComponentsInChildren<Collider>(true)) // collider.enabled = true; //var rb = obj.GetComponent<Rigidbody>(); //if (!rb) //{ // rb = obj.AddComponent<Rigidbody>(); //} //rb.useGravity = false; //rb.ResetCenterOfMass(); //rb.transform.localPosition = -rb.centerOfMass; }
/// <summary> /// Creates the beam effect for the predefined duration /// </summary> /// <returns></returns> private IEnumerator CreateBeamEffectForDuration(bool hitShield, ShipComponent targetComp) { //float currentTime = 0.0f; //line.enabled = true; //line.SetVertexCount(length); //Vector3 targetDir = (targetTrans.position - shootPoint.position).normalized; //while (currentTime <= effectDuration) //{ // CreateBeamEffect(targetDir); // currentTime += Time.deltaTime; // yield return null; //} //line.enabled = false; //Vector3 targetDir = (targetTrans.position - shootPoint.position).normalized; LaserEffectController laserClone = (LaserEffectController)Instantiate(laserEffectPrefab, shootPoint.position, shootPoint.rotation); yield return StartCoroutine(laserClone.PlayLaserEffect(effectDuration, hitShield? GetBeamImpactPoint(targetComp):targetTrans.position)); Destroy(laserClone.gameObject); }
void AddShip(Ship ship) { GameObject o = new GameObject(); o.name = "Ship_" + ship.Name; ShipComponent shipComponent = o.AddComponent <ShipComponent>(); shipComponents.Add(ship, shipComponent); GameObject tv = new GameObject(); tv.transform.SetParent(tacticalViewObject.transform); ShipTacticalViewComponent shipTacticalViewComponent = tv.AddComponent <ShipTacticalViewComponent>(); tv.name = "Ship_" + ship.Name + "_tv"; ship.register(shipComponent); ship.register(shipTacticalViewComponent); }
public void Interact() { _previousState = _currentState; _currentState = Mouse.GetState(); if (_focus != null) { float distance = Vector2.Distance(_position, _focus.GetPosition()); if (distance > interactRad) { // If player is too far from the Interactable Object (ie. ShipComponent) // then cancel current action and reset focus to a null value to prevent it from being interacted again from a distance _focus.Cancel(); _focus = null; _fixProgress.SetActive(false); return; } BreakableComponent b = _focus as BreakableComponent; if (_currentState.LeftButton == ButtonState.Released && _previousState.LeftButton == ButtonState.Pressed) { if (b != null) { if (b.IsBroken()) { Item item = _inventory.items.Find(i => i.itemType == b.GetRequiredItem()); if (item == null) { return; } _fixProgress.SetActive(true); } } _focus.Interact(); } if (b != null) { _fixProgress.UpdateProgress(b.GetFixProgress()); } } }
private ShipComponent GetFirstComponentInDirection(ShipComponent component) { Vector3 componentGridPos = trans.position + ComponentGridTrans.position; Vector3 targetCompPos = component.transform.position; Vector3 directionToTargetComp = targetCompPos - componentGridPos; //Ray ray = new Ray(componentGridPos, targetCompPos - componentGridPos); RaycastHit[] hits = Physics.RaycastAll(componentGridPos, directionToTargetComp, GlobalVars.RayCastRange); #if FULL_DEBUG if (hits == null || hits.Length == 0) Debug.LogError("No raycast hits"); #endif List<ShipComponent> hitComponents = new List<ShipComponent>(); foreach (RaycastHit hit in hits) { ShipComponent comp = hit.collider.GetComponent<ShipComponent>(); if (comp && comp.ParentShip != this && comp.ParentShip is AI_Ship) { hitComponents.Add(comp); } } #if FULL_DEBUG if (hitComponents == null || hitComponents.Count() == 0) Debug.LogError("No hit components"); #endif ShipComponent closestComp = hitComponents .Select(c => c.transform) .Aggregate((curr, next) => Vector3.Distance(curr.position, componentGridPos) < Vector3.Distance(next.position, componentGridPos) ? curr : next) .GetComponent<ShipComponent>(); #if FULL_DEBUG if (!closestComp) { Debug.LogError("No component found"); } #endif return closestComp; }
void ApplyUpgrades(ShipComponent c) { foreach (Upgrade u in upgrades) { if (c.GetComponent(u.typeName)&&u.bought) { u.ApplyUpgrade(c); } } }
void OnTargetShipComponentMouseOver(ShipComponent component) { #if FULL_DEBUG if(component==null) { Debug.LogError("point over component null") ; } #endif if (targetComponent) { targetComponent.Selected = false; } targetComponent = GetFirstComponentInDirection(component); if(!targetComponent) { Debug.LogWarning("No target comp "); return; } //Debug.Log("TargetComp: " + targetComponent + " from ship " + name); combatInterface.ShowToolTip(component.componentName, Input.mousePosition); DisplayLineRenderer(targetComponent.transform.position, true, validColour); targetComponent.Selected = true; }
void OnTargetShipComponentMouseOver(ShipComponent component) { if (targetComponent) targetComponent.Selected = false; targetComponent = GetFirstComponentInDirection(component); targetComponent.Selected = true; combatInterface.ShowToolTip(component.componentName, Input.mousePosition); DisplayLineRenderer(targetComponent.transform.position, Color.cyan); combatInterface.SetCursorType(CursorType.Attack); }
void OnTargetShipComponentClicked(ShipComponent component) { if (targetComponent) targetComponent.Selected = false; targetComponent = GetFirstComponentInDirection(component); targetComponent.Selected = true; //attack confirmed ChangeState(PlayerState.ActivateWeapons); TutorialSystem.Instance.ShowTutorial(TutorialSystem.TutorialType.ClickOnCompToFire, false); }
public ComponentTableEntry(int _ID, ShipComponent _component) { ID = _ID; component = _component; }
public void AutoGenIDandAdd(ShipComponent comp) { AddEntry(GenID(), comp); }
private IEnumerator ActivateWeapons() { if(TutorialSystem.Instance) { TutorialSystem.Instance.ShowTutorial(TutorialSystem.TutorialType.ClickOnCompToFire, false); } int numWeaponsActivated = 0; float totalPowerUsed = 0.0f; int originalCamCulling = Camera.main.cullingMask; EnableInputEvents(false); DisplayLineRenderer(Vector3.zero, false, validColour); ShowTargetingPanel(false); AllowEnemyTargeting(false); combatInterface.ShowStatsPanel(false); SubscribeToAIShipMouseEvents(false); targetComponent.Selected = false; combatInterface.ShowComponentHotkeyButtons(null, null); //combatInterface.ShowComponentSelectionPanel(false); targetShip.ShowHPBars(true); Camera.main.cullingMask = originalCamCulling | 1 << TagsAndLayers.ComponentsLayer | 1 << TagsAndLayers.ComponentSlotLayer; yield return StartCoroutine(CameraDirector.Instance.ZoomInFromAbove(targetComponent.ParentShip.transform, GlobalVars.CameraAimAtPeriod)); trans.LookAt(targetComponent.transform); if(TutorialSystem.Instance) { TutorialSystem.Instance.ShowTutorial(TutorialSystem.TutorialType.EnemyShieldHP, true); } if (selectedComponents.Any(c => !(c is Component_Weapon))) { Debug.LogError("Not weapon "); } foreach (Component_Weapon weapon in selectedComponents) { if (!targetShip || targetShip.HullHP<=0.0f) break; if (targetComponent && targetComponent.CompHP > 0.0f) { yield return StartCoroutine( weapon.Fire(targetComponent, () => { numWeaponsActivated--; totalPowerUsed += weapon.ActivationCost; })); numWeaponsActivated++; } } //waits until all weapons have completed their animation while (numWeaponsActivated > 0 && targetShip && targetShip.HullHP>0.0f) { Debug.LogWarning("targetship hp " + targetShip.HullHP); yield return null; } Camera.main.cullingMask = originalCamCulling; CurrentPower -= totalActivationCost; UnSelectComponents(false); combatInterface.ShowStatsPanel(true); attackTargetConfirmed = false; targetComponent = null; if (targetShip && targetShip.HullHP > 0.0f) { targetShip.ShowHPBars(false); SubscribeToAIShipMouseEvents(true); } else { Debug.Log("Acitvation - target dead"); startTargetingSequence = false; yield return StartCoroutine(CameraDirector.Instance.MoveToFocusOn(trans, GlobalVars.CameraMoveToFocusPeriod)); } //yield return StartCoroutine(CameraDirector.Instance.MoveToFocusOn(trans, GlobalVars.CameraMoveToFocusPeriod)); }
// Method to add a component to the starship. This will set the correct // bit in specialEffects. public void addComponent(ShipComponent toAdd) { specialEffects.Set(toAdd.bitIndex, true); }
private void SelectComponent(ShipComponent component, bool select) { if (select) { //selected comp is not the same component type as selected - restart selection if (selectedComponents.Count > 0 && component.GetType() != selectedComponents[0].GetType()) { UnSelectComponents(); } //not enough power - return without selecting if ((CurrentPower - totalActivationCost - component.ActivationCost) < 0) { #if FULL_DEBUG Debug.LogWarning("Not enough power"); #endif combatInterface.SetPowerValid(false); return; } //checks passed - select comp selectedComponents.Add(component); //tutorial next comp selection if (!allowingEnemyTargeting) AllowEnemyTargeting(true); ; totalActivationCost += component.ActivationCost; }//Select true else { #if FULL_DEBUG if (!selectedComponents.Contains(component)) { Debug.LogError("Selected components doesn't contain " + component.componentName); } #endif selectedComponents.Remove(component); if (selectedComponents.Count == 0) AllowEnemyTargeting(false); totalActivationCost -= component.ActivationCost; } component.Selected = select; combatInterface.UpdateStats(CurrentPower - totalActivationCost, MoveCost, true); }
void OnTargetShipComponentClicked(ShipComponent component) { #if FULL_DEBUG if(component==null) { Debug.LogError("point click component null") ; } #endif if(targetComponent) { targetComponent.Selected = false; } targetComponent = GetFirstComponentInDirection(component); targetComponent.Selected = true; attackTargetConfirmed = true; }
/// <summary> /// clicked on a component - toggle selection, start component selection sequnce if required /// </summary> /// <param name="component"></param> void OnComponentClicked(ShipComponent component) { SelectComponent(component, !selectedComponents.Contains(component)); }
private ShipComponent GetFirstComponentInDirection(ShipComponent component) { Ray ray = new Ray(trans.position + ComponentGridTrans.position, component.transform.position - (trans.position + ComponentGridTrans.position)); RaycastHit hit; if (Physics.Raycast(ray, out hit, GlobalVars.RayCastRange, 1 << TagsAndLayers.ComponentsLayer)) { return hit.collider.GetComponent<ShipComponent>(); } return component; }
private IEnumerator ComponentSelectionAndTargeting() { //stop listening to mouse events on ai ships SubscribeToAIShipMouseEvents(false); //show enemy target int targetShipIndex = 0; List<AI_Ship> aiShips = TurnBasedCombatSystem.Instance.ai_Ships; int numAIShips = aiShips.Count; #if FULL_DEBUG if (numAIShips == 0) { Debug.LogError("No ai ships found"); } #endif //targetShip = aiShips[targetShipIndex]; targetShipIndex = aiShips.IndexOf(targetShip); Transform aiTargetTrans = targetShip.transform; spaceGround.Display(false); //camera yield return StartCoroutine(CameraDirector.Instance.OverheadAimAt(trans, aiTargetTrans, GlobalVars.CameraAimAtPeriod)); //show comp seleciton panel combatInterface.EnableComponentSelectionPanel(true); combatInterface.ShowComponentSelectionPanel(true); //show hotkeys //combatInterface.ShowComponentHotkeyButtons(SelectAllComponents, components.Where(c => c.CanActivate)); ShowTargetingPanel(true); trans.LookAt(aiTargetTrans); InputManager.Instance.RegisterKeysDown(TargetNext, KeyCode.Tab); InputManager.Instance.RegisterKeysDown(StopTargetingSequence, KeyCode.Escape); TutorialSystem.Instance.ShowNextTutorial(TutorialSystem.TutorialType.ClickEnemyToEngage); while (!attackTargetConfirmed) { if (stopTargetingSequence) { startTargetingSequence = false; stopTargetingSequence = false; targetComponent = null; ShowTargetingPanel(false); combatInterface.ShowComponentSelectionPanel(false); InputManager.Instance.DeregisterKeysDown(TargetNext, KeyCode.Tab); InputManager.Instance.DeregisterKeysDown(StopTargetingSequence, KeyCode.Escape); yield return StartCoroutine(CameraDirector.Instance.MoveToFocusOn(trans, GlobalVars.CameraMoveToFocusPeriod)); break; } if (targetNext) { ShowTargetingPanel(false); targetShipIndex = ++targetShipIndex % numAIShips; targetShip = aiShips[targetShipIndex]; ShowTargetingPanel(true); aiTargetTrans = targetShip.transform; yield return StartCoroutine(CameraDirector.Instance.OverheadAimAt(trans, aiTargetTrans, GlobalVars.CameraAimAtPeriod)); trans.LookAt(aiTargetTrans); targetNext = false; } yield return null; } ShowTargetingPanel(false); SubscribeToAIShipMouseEvents(true); combatInterface.ShowComponentSelectionPanel(false); InputManager.Instance.DeregisterKeysDown(TargetNext, KeyCode.Tab); InputManager.Instance.DeregisterKeysDown(StopTargetingSequence, KeyCode.Escape); }
private IEnumerator PreTargetingEnemy() { #if FULL_DEBUG if (!targetShip) Debug.LogError("No target ship"); Debug.Log("PreTargetingMode"); #endif aiTrans = targetShip.transform; yield return StartCoroutine(CameraDirector.Instance.OverheadAimAt(trans, aiTrans, GlobalVars.CameraAimAtPeriod)); combatInterface.EnableComponentSelectionPanel(true); combatInterface.ShowComponentSelectionPanel(true); //combatInterface.ShowComponentHotkeyButtons(SelectAllComponents, components.Where(c => c.CanActivate)); combatInterface.ShowComponentHotkeyButtons(SelectAllComponents, components.Where(comp=>comp.CanActivate) .ToDictionary(comp=>comp,comp=>WeaponCanHitEnemy((Component_Weapon)comp))); ShowTargetingPanel(true); combatInterface.ShowModeButtons(true); combatInterface.EnableMoveButton(true, () => ChangeState(PlayerState.MovementMode)); combatInterface.EnableTacticalButton(true, () => ChangeState(PlayerState.TacticalView)); InputManager.Instance.RegisterKeysDown(SwitchToTacticalMode, KeyCode.Escape); TutorialSystem.Instance.ShowTutorial(TutorialSystem.TutorialType.ComponentPanel, true); spaceGround.Display(false); targetComponent = null; trans.LookAt(aiTrans); if(selectedComponents.Count>0) { SelectAllComponents(selectedComponents[0].GetType()); } }
void OnTargetShipComponentPointerExit(ShipComponent component) { #if FULL_DEBUG if(component==null) { Debug.LogError("point exit component null") ; } #endif if (targetComponent) { targetComponent.Selected = false; } if (component.Selected) { component.Selected = false; } combatInterface.HideTooltip(); }
/// <summary> /// Select the specified component - shows the effect and updates GUI to reflect potential power cost /// </summary> /// <param name="component"></param> /// <param name="select"></param> private void SelectComponent(ShipComponent component, bool select) { if (select) { if (!selectedComponents.Contains(component)) { //Debug.Log("select"); if(selectedComponents.Count>0) { //not the same component type as selected - restart selection if(component.GetType() != selectedComponents[0].GetType()) { UnSelectComponents(true); } } if (CurrentPower - totalActivationCost - component.ActivationCost < 0) { #if FULL_DEBUG Debug.LogWarning("Not enough power"); #endif combatInterface.SetPowerValid(false); return; } selectedComponents.Add(component); component.Selected = true; TutorialSystem.Instance.ShowNextTutorial(TutorialSystem.TutorialType.ComponentSelection); if (!allowingEnemyTargeting) AllowEnemyTargeting(true); totalActivationCost += component.ActivationCost; combatInterface.UpdateStats(CurrentPower - totalActivationCost, MoveCost,true); }//selected component contains } else //de-select { if(selectedComponents.Contains(component)) { selectedComponents.Remove(component); component.Selected = false; if(selectedComponents.Count==0) { AllowEnemyTargeting(false); } totalActivationCost -= component.ActivationCost; combatInterface.UpdateStats(CurrentPower - totalActivationCost, MoveCost,true); } } }
public void DestroyComponent(ShipComponent component) { components.Remove(component); Destroy(component); }