-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,179 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public enum ChallengeObjectiveTypeSCore : byte { | ||
ChallengeObjectiveEnterPOI, | ||
ChallengeObjectiveCompleteQuestStealth, | ||
ChallengeObjectiveKillWithItem, | ||
ChallengeObjectiveStealthKillStreak | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
Mods/0-SCore/Features/Challenges/Scripts/ChallengeObjectiveCompleteQuestStealth.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Xml.Linq; | ||
using HarmonyLib; | ||
using Challenges; | ||
using UnityEngine; | ||
|
||
namespace Challenges { | ||
|
||
/* | ||
* A new challenge objective to monitor your stealth kills during a quest. | ||
* To pass this challenge, you must do consecutive stealth kills until you've reached the desired count. | ||
* If the intention is that the full quest be done 100% stealth, set the count to be higher than the expected number of zombies | ||
* Once the Sleeper volumes are all cleared for the QuestObjectiveClear, then the challenge will complete, regardless if | ||
* the Count is equaled to the count specified. | ||
* | ||
* <!-- Kill two entities in a row with a stealth kill, during a quest. --> | ||
* <objective type="CompleteQuestStealth, SCore" count="2"/> | ||
* | ||
* <!-- Kill all entities in a row with a stealth kill, during a quest. --> | ||
* <objective type="CompleteQuestStealth, SCore" count="1000"/> | ||
*/ | ||
public class ChallengeObjectiveCompleteQuestStealth : BaseChallengeObjective { | ||
|
||
public override ChallengeObjectiveType ObjectiveType => | ||
(ChallengeObjectiveType)ChallengeObjectiveTypeSCore.ChallengeObjectiveCompleteQuestStealth; | ||
|
||
public override string DescriptionText => | ||
Localization.Get("ChallengeObjectiveCompleteQuestStealth"); | ||
|
||
public override void Init() { | ||
} | ||
|
||
public override void HandleAddHooks() { | ||
EventOnRallyPointActivated.OnActivated += OnQuestActivated; | ||
} | ||
|
||
private void Reset() { | ||
Current = 0; | ||
Complete = false; | ||
HandleRemoveHooks(); | ||
} | ||
|
||
public override void HandleRemoveHooks() { | ||
EventOnRallyPointActivated.OnActivated -= OnQuestActivated; | ||
QuestEventManager.Current.SleepersCleared -= Current_SleepersCleared; | ||
EventOnClientKill.OnClientKillEvent -= Current_EntityDamaged; | ||
} | ||
|
||
// Start listening to the other hooks only after we've activated a quest. | ||
private void OnQuestActivated() { | ||
Reset(); | ||
EventOnClientKill.OnClientKillEvent += Current_EntityDamaged; | ||
QuestEventManager.Current.SleepersCleared += Current_SleepersCleared; | ||
} | ||
|
||
// The only way this event should still be listened to here, is if we didn't end the kill streak. | ||
private void Current_SleepersCleared(Vector3 prefabPos) { | ||
Current = MaxCount; | ||
CheckObjectiveComplete(); | ||
} | ||
private bool Current_EntityDamaged(DamageResponse _dmresponse, EntityAlive entityDamaged) { | ||
// We didn't damage the zombie. Don't count it. | ||
var entityId = _dmresponse.Source.getEntityId(); | ||
if (entityId == -1) return false; | ||
|
||
var player = GameManager.Instance.World.GetEntity(entityId) as EntityPlayerLocal; | ||
if (player == null) return false; | ||
|
||
// Is the zombies still without the bounds? | ||
var position = entityDamaged.position; | ||
position.y = position.z; | ||
if (!player.ZombieCompassBounds.Contains(position)) return false; | ||
|
||
// Were we sneaking? | ||
if (_dmresponse.Source.BonusDamageType != EnumDamageBonusType.Sneak) | ||
{ | ||
Reset(); | ||
return false; | ||
} | ||
|
||
// Check to see if we have a max counter to complete the challenge. | ||
Current++; | ||
CheckObjectiveComplete(); | ||
return true; | ||
} | ||
|
||
public override BaseChallengeObjective Clone() { | ||
return new ChallengeObjectiveCompleteQuestStealth { | ||
|
||
}; | ||
} | ||
|
||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
Mods/0-SCore/Features/Challenges/Scripts/ChallengeObjectiveKillWithItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Xml.Linq; | ||
using HarmonyLib; | ||
using Challenges; | ||
using UnityEngine; | ||
using UnityEngine.Animations; | ||
|
||
namespace Challenges { | ||
/* | ||
* | ||
* To pass this challenge, you must killed zombies with the specified item. This extends the KillByTag objective, and thus supports | ||
* all those attributes as well. Multiple item="" can be listed as a comma-delimited list. | ||
* | ||
* <!-- Kill two zombies in a row with a gunHandgunT1Pistol --> | ||
* <objective type="KillWithItem, SCore" count="2" item="gunHandgunT1Pistol" /> | ||
* | ||
* Rather than item name itself, you could also use item_tag | ||
* <objective type="KillWithItem, SCore" count="2" item_tags="handgunSkill" /> | ||
* | ||
* ItemName is checked first, then item tags. If either passes, then vanilla code is checked for the other tags and checks. | ||
* | ||
* You may also add the option entity tags and target_name_key for localization. | ||
* By default, the entity_tags and target_name_key is zombie and xuiZombies, respectively. | ||
* <objective type="KillWithItem, SCore" count="2" item="gunHandgunT1Pistol" entity_tags="zombie" target_name_key="xuiZombies" /> | ||
* | ||
* Other attributes available are: | ||
* target_name="zombieMarlene" | ||
* biome="snow" | ||
* killer_has_bufftag="buff_tags" | ||
* killed_has_bufftag="buff_tags" | ||
* is_twitch_spawn="true/false" | ||
*/ | ||
public class ChallengeObjectiveKillWithItem : ChallengeObjectiveKillByTag { | ||
public override ChallengeObjectiveType ObjectiveType => | ||
(ChallengeObjectiveType)ChallengeObjectiveTypeSCore.ChallengeObjectiveKillWithItem; | ||
|
||
public string ItemClass; | ||
public string ItemTag; | ||
public bool StealthCheck; | ||
public string LocalizationKey = "challengeObjectiveKillWithItem"; | ||
|
||
public override void Init() { | ||
if ( string.IsNullOrEmpty(entityTag)) | ||
entityTag = "zombie"; | ||
if ( string.IsNullOrEmpty(targetName)) | ||
targetName = Localization.Get("xuiZombies"); | ||
base.Init(); | ||
} | ||
|
||
public override string DescriptionText { | ||
get { | ||
var objectiveDesc = Localization.Get(LocalizationKey); | ||
objectiveDesc = objectiveDesc.Replace("[]", MaxCount.ToString()); | ||
if (!string.IsNullOrEmpty(ItemClass)) | ||
{ | ||
// Use a counter to know if there needs to be ,'s | ||
var itemDisplay = $" {Localization.Get("challengeObjectiveWith")} "; | ||
var counter = 0; | ||
foreach (var item in ItemClass.Split(',')) | ||
{ | ||
if (counter>0) | ||
itemDisplay += ", "; | ||
itemDisplay += $"{Localization.Get(item)}"; | ||
counter++; | ||
} | ||
|
||
return $"{objectiveDesc} {itemDisplay}"; | ||
} | ||
|
||
if (string.IsNullOrEmpty(ItemTag)) return base.DescriptionText; | ||
var itemWithTags = Localization.Get("itemWithTags"); | ||
return $"{objectiveDesc} {itemWithTags} {ItemTag}"; | ||
|
||
} | ||
} | ||
|
||
public override void HandleAddHooks() { | ||
EventOnClientKill.OnClientKillEvent += Check_EntityKill; | ||
} | ||
|
||
public override void HandleRemoveHooks() { | ||
EventOnClientKill.OnClientKillEvent -= Check_EntityKill; | ||
} | ||
|
||
public virtual bool HasPrerequisiteCondition(DamageResponse dmgResponse) { | ||
if (!dmgResponse.Fatal) return false; | ||
if (StealthCheck) | ||
{ | ||
if (dmgResponse.Source.BonusDamageType != EnumDamageBonusType.Sneak) return false; | ||
} | ||
|
||
if (SCoreChallengeUtils.IsKilledByTrap(dmgResponse, ItemClass)) return true; | ||
if (SCoreChallengeUtils.IsHoldingItemName(ItemClass)) return true; | ||
if (SCoreChallengeUtils.IsHoldingItemHasTag(ItemTag)) return true; | ||
return false; | ||
} | ||
|
||
|
||
// If we pass the pre-requisite, call the base class of the KillWithTags to do the heavy lifting for us. | ||
protected virtual bool Check_EntityKill(DamageResponse _dmresponse, EntityAlive killedEntity) { | ||
if (!HasPrerequisiteCondition(_dmresponse)) return false; | ||
var player = GameManager.Instance.World.GetPrimaryPlayer(); | ||
base.Current_EntityKill(player, killedEntity); | ||
return true; | ||
} | ||
|
||
public override void ParseElement(XElement e) { | ||
base.ParseElement(e); | ||
if (e.HasAttribute("item")) | ||
{ | ||
ItemClass = e.GetAttribute("item"); | ||
} | ||
|
||
if (e.HasAttribute("item_tag")) | ||
{ | ||
ItemTag = e.GetAttribute("item_tag"); | ||
} | ||
|
||
if (e.HasAttribute("stealth")) | ||
{ | ||
var temp = e.GetAttribute("stealth"); | ||
StringParsers.TryParseBool(temp, out StealthCheck); | ||
} | ||
|
||
} | ||
|
||
public override BaseChallengeObjective Clone() { | ||
return new ChallengeObjectiveKillWithItem { | ||
entityTag = entityTag, | ||
entityTags = entityTags, | ||
biome = biome, | ||
targetName = targetName, | ||
isTwitchSpawn = isTwitchSpawn, | ||
killerHasBuffTag = killerHasBuffTag, | ||
killedHasBuffTag = killedHasBuffTag, | ||
ItemClass = ItemClass, | ||
ItemTag = ItemTag, | ||
StealthCheck = StealthCheck | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.