public void ApplyTo(PowerupManager car) { if (attached) { return; } attached = true; PowerupAttachable pAttachable = GetComponent <PowerupAttachable>(); PowerupEvent pEvent = GetComponent <PowerupEvent>(); PowerupBoost pBoost = GetComponent <PowerupBoost>(); PowerupStats pStats = GetComponent <PowerupStats>(); if (pAttachable != null) { appliedManager = car.Attach(pAttachable, pAttachable.attachType); } else if (pEvent != null) { appliedManager = car.AddEvent(pEvent); } else if (pBoost != null) { appliedManager = car.ApplyBoost(pBoost); } }
public void ShowPotentialItem(GameObject item) { PowerupMain main = item.GetComponent <PowerupMain>(); PowerupAttachable attach = item.GetComponent <PowerupAttachable>(); StatPack pack = item.GetComponent <PowerupStats>().GetPack(); PowerupAttachable otherItem; StatPack otherPack; if (main.IsEquipped()) { return; } if (attach.isWeapon) { otherItem = controller.GetCar().GetComponent <PowerupManager>().GetWeapon(attach.weaponLocation); damageSliders.ShowPotentialWeapon(attach); } else { otherItem = controller.GetCar().GetComponent <PowerupManager>().GetMod(attach.modLocation); } if (otherItem == null) { otherPack = new StatPack(); } else { otherPack = otherItem.GetComponent <PowerupStats>().GetPack(); } ShowStatBars(pack, otherPack); }
public void SetOwned(bool owned) { isOwned = owned; if (!isOwned) { isEquipped = false; return; } string name = gameObject.name; PowerupAttachable attachInfo = gameObject.GetComponent <PowerupAttachable>(); string location; if (attachInfo.isWeapon) { location = attachInfo.weaponLocation.ToString(); } else { location = attachInfo.modLocation.ToString(); } string saveData = location + ":" + name; string unlocks = PlayerPrefs.GetString("Unlocks"); if (!unlocks.Contains(saveData)) { if (unlocks.Length == 0) { PlayerPrefs.SetString("Unlocks", saveData); } else { PlayerPrefs.SetString("Unlocks", unlocks + "," + saveData); } } }
private void SendStats(StatPack stats, PowerupAttachable attachable) { if (attachable.isWeapon) { GarageStats.TryUpdate(stats, attachable.weaponLocation, attachable.baseDamage); } else { GarageStats.TryUpdate(stats, attachable.modLocation); } }
public void ShowUnequippedItem(ModMount mount) { StatPack pack = new StatPack(); PowerupAttachable otherItem = controller.GetCar().GetComponent <PowerupManager>().GetMod(mount); if (otherItem == null) { return; } StatPack otherPack = otherItem.GetComponent <PowerupStats>().GetPack(); ShowStatBars(pack, otherPack); }
public void ShowUnequippedItem(WeaponMount mount) { StatPack pack = new StatPack(); PowerupAttachable otherItem = controller.GetCar().GetComponent <PowerupManager>().GetWeapon(mount); if (otherItem == null) { return; } StatPack otherPack = otherItem.GetComponent <PowerupStats>().GetPack(); ShowStatBars(pack, otherPack); damageSliders.ShowPotentialWeapon(mount, controller.GetCar().GetComponent <PowerupManager>().baseDamage); }
private void OnCollisionEnter2D(Collision2D collision) { PowerupAttachable attachable = gameObject.GetComponent <PowerupAttachable>(); if (attachable != null) { appliedManager.NotifyCollision(collision, attachable); } else { if (collision.otherCollider.gameObject.tag == "Player") { ApplyTo(collision.otherCollider.gameObject.GetComponent <PowerupManager>()); } } }
public void ShowPotentialWeapon(PowerupAttachable weapon) { ShowPotentialWeapon(weapon.weaponLocation, weapon.baseDamage); }
public PowerupManager Attach(PowerupAttachable attachment, AttachType aType) { if (attachment.isWeapon) { WeaponMount slot = attachment.weaponLocation; List <Joint> attachJoints = new List <Joint>(); List <GameObject> newWeapons = new List <GameObject>(); if (equippedWeapons.ContainsKey(slot)) { equippedWeapons[slot].GetComponent <PowerupMain>().UnEquip(); } equippedWeapons[slot] = attachment; if (physicalWeapons.ContainsKey(slot)) { foreach (GameObject oldWeapon in physicalWeapons[slot]) { Destroy(oldWeapon); } } switch (slot) { case WeaponMount.Grill: attachJoints.Add(Joint.FBumper); break; case WeaponMount.Hitch: attachJoints.Add(Joint.RBumper); break; case WeaponMount.Doors: attachJoints.Add(Joint.LDoor); attachJoints.Add(Joint.RDoor); break; case WeaponMount.Roof: attachJoints.Add(Joint.Center); break; case WeaponMount.Wheels: attachJoints.Add(Joint.FLTire); attachJoints.Add(Joint.FRTire); attachJoints.Add(Joint.BLTire); attachJoints.Add(Joint.BRTire); break; } foreach (Joint joint in attachJoints) { FixedJoint2D tJoint = joints[joint]; PowerupAttachable newAttachment = Instantiate(attachment.gameObject).GetComponent <PowerupAttachable>(); newAttachment.GetComponent <PowerupMain>().SetManager(this); newWeapons.Add(newAttachment.gameObject); newAttachment.SetAnchor(joint); if (joint == Joint.BLTire || joint == Joint.FLTire || joint == Joint.LDoor) { newAttachment.gameObject.transform.localScale = new Vector3(-1, 1, 1); newAttachment.gameObject.transform.position = gameObject.transform.position + new Vector3(tJoint.anchor.x, tJoint.anchor.y, 0f) - new Vector3(newAttachment.anchorOverride.x, newAttachment.anchorOverride.y, 0); } else { newAttachment.gameObject.transform.position = gameObject.transform.position + new Vector3(tJoint.anchor.x, tJoint.anchor.y, 0f) + new Vector3(newAttachment.anchorOverride.x, newAttachment.anchorOverride.y, 0); } switch (aType) { case AttachType.Spring: tJoint.connectedBody = newAttachment.gameObject.GetComponent <Rigidbody2D>(); tJoint.connectedAnchor = newAttachment.anchorOverride; tJoint.enabled = true; break; case AttachType.Fixed: default: newAttachment.gameObject.transform.parent = gameObject.transform; break; } } physicalWeapons[slot] = newWeapons; } else { if (equippedMods.ContainsKey(attachment.modLocation)) { equippedMods[attachment.modLocation].GetComponent <PowerupMain>().UnEquip(); } equippedMods[attachment.modLocation] = attachment; } attachment.GetComponent <PowerupMain>().Equip(); ReCalcStats(); return(this); }