Skip to content

Commit

Permalink
test: add deployableapi test (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiao921 authored Sep 10, 2024
1 parent 5b0ce6f commit 5e8ea0b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions R2API.Test/R2API.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ProjectReference Include="../R2API.Director/R2API.Director.csproj" />
<ProjectReference Include="../R2API.Elites/R2API.Elites.csproj" />
<ProjectReference Include="../R2API.SceneAsset/R2API.SceneAsset.csproj" />
<ProjectReference Include="../R2API.Deployable/R2API.Deployable.csproj" />

</ItemGroup>

Expand Down
58 changes: 58 additions & 0 deletions R2API.Test/Tests/ConCommandTests/DeployableAPITests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using RoR2;
using UnityEngine.Events;
using UnityEngine;
using UnityEngine.AddressableAssets;

namespace R2API.Test.Tests.ConCommandTests;

public static class DeployableAPITests
{
private static DeployableSlot myDeployableSlotIndex = DeployableSlot.None;
private static bool registerOnce = true;

[ConCommand(commandName = "add_deployable_test")]
private static void AddDeployableTest(ConCommandArgs args)
{
if (registerOnce)
{
myDeployableSlotIndex = DeployableAPI.RegisterDeployableSlot((characterMaster, oldLimit) =>
{
return 3;
});

registerOnce = false;
}

Debug.LogError("[DeployableAPITests] myDeployableSlotIndex: " + myDeployableSlotIndex);

var position = PlayerCharacterMasterController.instances[0].body.transform.position;
var body = PlayerCharacterMasterController.instances[0].body;
var summoner = PlayerCharacterMasterController.instances[0].body.gameObject;

DirectorSpawnRequest directorSpawnRequest = new DirectorSpawnRequest(Addressables.LoadAssetAsync<CharacterSpawnCard>("RoR2/Base/Golem/cscGolemSnowy.asset").WaitForCompletion(), new DirectorPlacementRule
{
placementMode = DirectorPlacementRule.PlacementMode.Direct,
minDistance = 0f,
maxDistance = 0f,
position = position
}, RoR2Application.rng);
directorSpawnRequest.summonerBodyObject = summoner;
GameObject gameObject = DirectorCore.instance.TrySpawnObject(directorSpawnRequest);
if (gameObject)
{
CharacterMaster component = gameObject.GetComponent<CharacterMaster>();
Inventory component2 = gameObject.GetComponent<Inventory>();
component2.SetEquipmentIndex(body.inventory.currentEquipmentIndex);
if (body.inventory.GetItemCount(RoR2Content.Items.Ghost) > 0)
{
component2.GiveItem(RoR2Content.Items.Ghost, 1);
component2.GiveItem(RoR2Content.Items.HealthDecay, 30);
component2.GiveItem(RoR2Content.Items.BoostDamage, 150);
}
Deployable deployable = gameObject.AddComponent<Deployable>();
deployable.onUndeploy = new UnityEvent();
deployable.onUndeploy.AddListener(new UnityAction(component.TrueKill));
body.master.AddDeployable(deployable, myDeployableSlotIndex);
}
}
}

0 comments on commit 5e8ea0b

Please sign in to comment.