Implement random number prim

This commit is contained in:
Nahuel Rocchetti 2023-08-24 13:50:53 -03:00
parent 4d3fe674f5
commit 5b206ce748
3 changed files with 39 additions and 0 deletions

View file

@ -14,6 +14,7 @@ namespace OpenTS2.SimAntics.Primitives
{
RegisterPrimitive<VMSleep>(0x0);
RegisterPrimitive<VMExpression>(0x2);
RegisterPrimitive<VMRandomNumber>(0x8);
RegisterPrimitive<VMRemoveObjectInstance>(0x12);
RegisterPrimitive<VMNotifyStackObjectOutOfIdle>(0x31);
}

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenTS2.SimAntics.Primitives
{
public class VMRandomNumber : VMPrimitive
{
public override VMReturnValue Execute(VMContext ctx)
{
var lhsSource = (VMDataSource)ctx.Node.GetOperand(2);
var lhsData = ctx.Node.GetInt16Operand(0);
var rhsSource = (VMDataSource)ctx.Node.GetOperand(6);
var rhsData = ctx.Node.GetInt16Operand(4);
var randomMaxValue = ctx.GetData(rhsSource, rhsData);
var randomFinalValue = (short)UnityEngine.Random.Range(0, randomMaxValue);
ctx.SetData(lhsSource, lhsData, randomFinalValue);
return VMReturnValue.ReturnTrue;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f67753d3b8a97c442b581b3a03d97f53
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: