Skip to content
Snippets Groups Projects
Commit 5c43e187 authored by Chiquita Ahsanunnisa's avatar Chiquita Ahsanunnisa
Browse files

feat: cheats

parent fcda188d
1 merge request!55fix/pet + cheat init
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Unity.Properties;
using UnityEngine;
using UnityEngine.UIElements;
[UxmlElement]
......@@ -37,6 +38,12 @@ public partial class CurrencyContainer : VisualElement
void UpdateText()
{
if (GameController.Instance != null && GameController.Instance.cheatController.MOTHERLODE)
{
currencyLabel.text = "MOTHERLODE!! " + Currency.ToString();
return;
}
currencyLabel.text = Currency.ToString();
}
......
......@@ -59,7 +59,9 @@ public class ShopController : InGameUIScreenController
Companion newCompanion = Companion.NewCompanionByType(newCompanionType);
GameController.Instance.player.AddCompanion(newCompanion, newCompanionType);
GameSaveManager.Instance.GetActiveGameSave().currencyData.AddTransaction(-10, "Buy pet");
int price = GameController.Instance.cheatController.MOTHERLODE ? 0 : 10;
GameSaveManager.Instance.GetActiveGameSave().currencyData.AddTransaction(-price, "Buy pet");
Debug.Log(String.Format("Number of companion ${0}", GameController.Instance.player.CompanionList.Count));
});
......
using System;
using System.Collections.Generic;
using UnityEngine;
public class CheatCommand
{
private static readonly StatEffect x2SpeedEffect = new(
"x2_speed",
StatEffectType.SPEED,
StatEffectType.MULTIPLICATION,
2f
);
private static int GetCurrentLevel()
{
if (!GameSaveManager.Instance.GetActiveGameSave().storyData.IsEventComplete(StoryConfig.KEY_STORY_2_START_CUTSCENE))
{
return 1;
}
else if (!GameSaveManager.Instance.GetActiveGameSave().storyData.IsEventComplete(StoryConfig.KEY_STORY_3_START_CUTSCENE))
{
return 2;
}
else if (!GameSaveManager.Instance.GetActiveGameSave().storyData.IsEventComplete(StoryConfig.KEY_STORY_4_START_CUTSCENE))
{
return 3;
}
else
{
return 4;
}
}
public static readonly Dictionary<string, Action> cheatCommands = new(){
{ "no_damage", () => { throw new NotImplementedException(); }},
{ "1_hit_kill", () => { throw new NotImplementedException(); }},
{ "motherlode", () => { throw new NotImplementedException(); }},
{ "x2_speed", () => { GameController.Instance.player.Speed *= 2; }},
{ "full_hp_pet", () => { throw new NotImplementedException(); }},
{ "kill_pet", () => { throw new NotImplementedException(); }},
{ "orb", () => { throw new NotImplementedException(); }},
{ "skip", () => { throw new NotImplementedException(); }},
{ "no_damage",
() => {
GameController.Instance.cheatController.NO_DAMAGE = true;
}
},
{ "one_hit_kill",
() => {
GameController.Instance.cheatController.ONE_HIT_KILL = true;
}
},
{ "motherlode",
() => {
GameController.Instance.cheatController.MOTHERLODE = true;
}
},
{ "x2_speed",
() => {
GameController.Instance.player.effects.Add(x2SpeedEffect);
}
},
{ "full_hp_pet",
() => {
GameController.Instance.cheatController.FULL_HP_PET = true;
}
},
{ "kill_pet",
() => {
GameController.Instance.player.StartCoroutine(
GameController.Instance.player.KillAllCompanions()
);
}
},
{ "orb",
() => {
// Generate a random orb near the player, not on the player
Vector3 orbPos = GameController.Instance.player.transform.position + new Vector3(1, 0, 0);
Orb.GenerateRandomOrb(orbPos, "Random Cheat Orb");
}
},
{ "skip",
() => {
int currentLevel = GetCurrentLevel();
Debug.Log("Current level: " + currentLevel);
if (currentLevel == 1)
{
GameSaveManager.Instance.GetActiveGameSave().storyData.CompleteEvent(StoryConfig.KEY_STORY_1_START_CUTSCENE);
GameSaveManager.Instance.GetActiveGameSave().storyData.CompleteEvent(StoryConfig.KEY_STORY_1_ENTER_DUNGEON);
GameSaveManager.Instance.GetActiveGameSave().storyData.CompleteEvent(StoryConfig.KEY_STORY_1_END_CUTSCENE);
GameController.Instance.player.transform.position = new Vector3(-33.1f, 0.073f, 190.17f); // Teleport to start of level 2
} else if (currentLevel == 2)
{
GameSaveManager.Instance.GetActiveGameSave().storyData.CompleteEvent(StoryConfig.KEY_STORY_2_START_CUTSCENE);
GameSaveManager.Instance.GetActiveGameSave().storyData.CompleteEvent(StoryConfig.KEY_STORY_2_END_CUTSCENE);
GameController.Instance.player.transform.position = new Vector3(-206.1f, 0.073f, 239.76f); // Teleport to start of level 3
} else if (currentLevel == 3)
{
GameSaveManager.Instance.GetActiveGameSave().storyData.CompleteEvent(StoryConfig.KEY_STORY_3_START_CUTSCENE);
GameSaveManager.Instance.GetActiveGameSave().storyData.CompleteEvent(StoryConfig.KEY_STORY_3_END_CUTSCENE);
GameController.Instance.player.transform.position = new Vector3(-231.13f, 0.073f, 179.6f); // Teleport to start of level 4
} else if (currentLevel == 4)
{
GameSaveManager.Instance.GetActiveGameSave().storyData.CompleteEvent(StoryConfig.KEY_STORY_4_START_CUTSCENE);
GameController.Instance.StartCutscene(StoryConfig.KEY_STORY_ENDING_CUTSCENE);
GameSaveManager.Instance.GetActiveGameSave().storyData.CompleteEvent(StoryConfig.KEY_STORY_ENDING_CUTSCENE);
GameController.Instance.StartCutscene(StoryConfig.KEY_STORY_ENDING_AFTER_CUTSCENE);
GameSaveManager.Instance.GetActiveGameSave().storyData.CompleteEvent(StoryConfig.KEY_STORY_ENDING_AFTER_CUTSCENE);
GameController.Instance.stateController.PopState();
GameController.Instance.stateController.PushState(GameState.FINISH);
}
}
},
};
}
......@@ -36,12 +36,6 @@ public abstract class BossEntity : EnemyEntity, IAccompaniable
{
CompanionActive.Add(false);
}
CompanionList.AddRange(EntityManager.Instance.GetComponentsInChildren<Companion>());
for (int i = initialIndex; i < CompanionList.Count; i++)
{
CompanionActive.Add(CompanionList[i].gameObject.activeSelf);
}
}
public void ActivateCompanion(int index)
......
public class GameCheatController
{
public bool FULL_HP_PET = false;
public bool NO_DAMAGE = false;
public bool ONE_HIT_KILL = false;
public bool MOTHERLODE = false;
}
\ No newline at end of file
fileFormatVersion: 2
guid: ac2263bbd34db96488fcd4f3a5fd025e
\ No newline at end of file
......@@ -10,6 +10,7 @@ public class GameController : MonoBehaviour
public Player player;
public GameCameraController mainCamera;
public GameStateController stateController;
public GameCheatController cheatController;
// Cheat Attributes
private float cheatDelayTimer;
......@@ -26,6 +27,7 @@ public class GameController : MonoBehaviour
GameController()
{
stateController = new();
cheatController = new();
}
protected void Awake()
......
......@@ -51,12 +51,6 @@ public class Player : PlayerEntity
CompanionActive.Add(true);
}
CompanionList.AddRange(EntityManager.Instance.GetComponentsInChildren<Companion>());
for (int i = initialIndex; i < CompanionList.Count; i++)
{
CompanionActive.Add(CompanionList[i].gameObject.activeSelf);
}
ActivateAllCompanions();
}
......
......@@ -11,29 +11,32 @@ public class AttackObject : MonoBehaviour, IDamaging, IKnockback
// Events
public event Action OnDamageEvent;
// Set-Getters
public float Damage {
get => damage;
set => damage = value;
public float Damage
{
get => damage;
set => damage = value;
}
public float KnockbackPower {
get => knockbackPower;
set => knockbackPower = value;
public float KnockbackPower
{
get => knockbackPower;
set => knockbackPower = value;
}
public Vector3 KnockbackOrigin{
public Vector3 KnockbackOrigin
{
get => transform.position + knockbackOffset;
set => knockbackOffset = KnockbackOrigin - transform.position;
}
// Constructor
protected void Start()
{
if(KnockbackOrigin == null)
if (KnockbackOrigin == null)
{
KnockbackOrigin = Vector3.zero;
}
}
}
// Functions
......@@ -45,29 +48,57 @@ public class AttackObject : MonoBehaviour, IDamaging, IKnockback
}
protected bool Hit(Collider otherCollider)
{
{
// Note: Hitboxes are traditionally placed within a model, therefore we get the damageable component from its parent
Transform objectParent = otherCollider.transform.parent;
if(objectParent == null)
if (objectParent == null)
{
return true;
}
objectParent.TryGetComponent<IDamageable>(out var damageableObject);
if(damageableObject == null)
if (damageableObject == null)
{
return true;
}
if(damageableObject.Damageable)
}
if (damageableObject.Damageable)
{
Debug.Log($"Hit in hitbox of {transform.name} by {objectParent.name} with damage of {Damage}");
Debug.Log($"Attack object from layer: {gameObject.layer}, {LayerMask.LayerToName(gameObject.layer)}");
bool isVictimPlayer = objectParent.gameObject.TryGetComponent<Player>(out var _);
bool isVictimPlayerPet = objectParent.gameObject.TryGetComponent<AttackingPet>(out var _) || objectParent.gameObject.TryGetComponent<HealingPet>(out var _);
bool isPlayerAttacker = LayerMask.LayerToName(gameObject.layer) == EnvironmentConfig.LAYER_PLAYER_ATTACK;
// CHEAT CHECKING
// Player
if (isVictimPlayer && GameController.Instance.cheatController.NO_DAMAGE)
{
Debug.Log("NO_DAMAGE cheat is active! Skipping damage.");
return false;
}
// Player's Pet
if (isVictimPlayerPet && GameController.Instance.cheatController.FULL_HP_PET)
{
Debug.Log("FULL_HP_PET cheat is active! Skipping damage.");
return false;
}
// Player attacking with one hit kill
if (isPlayerAttacker && GameController.Instance.cheatController.ONE_HIT_KILL)
{
Debug.Log("ONE_HIT_KILL cheat is active! Inflicting damage.");
Damage = damageableObject.Health;
}
damageableObject.InflictDamage(Damage);
OnDamageEvent?.Invoke();
objectParent.TryGetComponent<IRigid>(out var rigidObject);
if(rigidObject != null)
if (rigidObject != null)
{
Knockback(rigidObject);
}
......
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
public class PlayerEntity : CombatantEntity, IAccompaniable
{
......@@ -149,4 +150,14 @@ public class PlayerEntity : CombatantEntity, IAccompaniable
ActivateCompanion(i);
}
}
public IEnumerator KillAllCompanions()
{
yield return new WaitForSeconds(2);
for (int i = 0; i < companionList.Count; i++)
{
Destroy(companionList[i].gameObject);
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment