// 8: GetAll private static EventSubject <GameEntityModel> .GetSubjectsDelegate GetAll(Storage.GenericParameter parameter) { return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ List <GameEntityModel> subjects = new List <GameEntityModel>(); GameEntityModel subject; WorldModel world = StateManager.state.MainModel as WorldModel; TeamsManagerModel teamsModel = StateManager.state.GetModel(world.teamsModelId) as TeamsManagerModel; for (int i = 0; i < teamsModel.teams.Length; ++i) { TeamData teamData = teamsModel.teams[i]; if (teamData != null && teamData.entities != null) { foreach (ModelReference modelRef in teamData.entities) { subject = StateManager.state.GetModel(modelRef) as GameEntityModel; if (subject != null) { subjects.Add(subject); } } } } return subjects; }); }
private static EventAction <GameEntityModel> .ExecutionDelegate BuildGetHurt(Storage.GenericParameter parameter) { int hittersSubjectId = parameter.SafeInt(1); int numeratorSubjectId = parameter.SafeInt(2); string numeratorVariableName = parameter.SafeString(0); int defaultPercentage = parameter.SafeInt(3); int facingOptions = parameter.SafeInt(4); return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ List <GameEntityModel> hitterSubjects = ConditionUtils <GameEntityModel> .GetNonEmptySubjectOrNil(subjectModels, hittersSubjectId); if (hitterSubjects == null || hitterSubjects.Count == 0) { return; } FixedFloat percentage = GetNumeratorValue(model, numeratorSubjectId, numeratorVariableName, defaultPercentage, subjectModels); percentage /= 100; switch (facingOptions) { case -1: // Use hit data GameEntityController.HurtBasedOnHitData(model, percentage, hitterSubjects); break; default: // Use given facing options GameEntityController.HurtBasedOnFacingOptions(model, (HitData.HitFacing)facingOptions, percentage, hitterSubjects); break; } }); }
// 0: GetSelf private static EventSubject <GameEntityModel> .GetSubjectsDelegate GetSelf(Storage.GenericParameter parameter) { // Create the delegate return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ return CreateSubjectsWithSubject(model); }); }
// Build a point static FixedVector3 BuildFixedVector3(Storage.GenericParameter parameter, int startFloatIndex = 0) { FixedFloat x = parameter.SafeFloat(startFloatIndex); FixedFloat y = parameter.SafeFloat(startFloatIndex + 1); FixedFloat z = parameter.SafeFloat(startFloatIndex + 2); return(new FixedVector3(x, y, z)); }
// The public builder method public static HitData Build(Storage.GenericParameter param) { int callIndex = param.type; if (callIndex < builderActions.Length) { return(builderActions[callIndex](param)); } Debug.Log("CharacterHitsBuilder: Unknown hit type: " + param.type); return(null); }
// 3: GetParent private static EventSubject <GameEntityModel> .GetSubjectsDelegate GetParent(Storage.GenericParameter parameter) { int subjectId = parameter.SafeInt(0); return(DefaultDelegation(subjectId, delegate(GameEntityModel model, List <GameEntityModel> subjects){ GameEntityModel parentModel = StateManager.state.GetModel(model.parentEntity) as GameEntityModel; if (parentModel != null) { subjects.Add(parentModel); } })); }
// Build a single subject private static EventSubject <GameEntityModel> BuildFromParameter(Storage.GenericParameter parameter, int initialIndex) { EventSubject <GameEntityModel> .GetSubjectsDelegate getSubjectDelegate; EventSubject <GameEntityModel> .ReevaluateSubjectsDelegate reevaluateSubject; int callIndex = parameter.type; if (callIndex < builderActions.Length) { getSubjectDelegate = builderActions[initialIndex + callIndex](parameter); reevaluateSubject = GetReevaluateSubject(parameter); return(new EventSubject <GameEntityModel>(getSubjectDelegate, reevaluateSubject)); } Debug.Log("CharacterSubjectsBuilder: Unknown subject type: " + parameter.type); return(null); }
// Build a single event private static EventAction <GameEntityModel> BuildFromParameter(Storage.GenericParameter parameter) { EventAction <GameEntityModel> .ExecutionDelegate executionDelegate; int callIndex = parameter.type; int subjectId; if (callIndex < builderActions.Length) { executionDelegate = builderActions[callIndex](parameter); subjectId = GetSubjectId(parameter); return(new EventAction <GameEntityModel>(executionDelegate, subjectId)); } Debug.Log("CharacterActionsBuilder: Unknown condition type: " + parameter.type); return(null); }
private static EventAction <GameEntityModel> .ExecutionDelegate BuildGrab(Storage.GenericParameter parameter) { int subjectId = parameter.SafeInt(1); int anchorId = parameter.SafeInt(2); return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ List <GameEntityModel> refSubjects = ConditionUtils <GameEntityModel> .GetNonEmptySubjectOrNil(subjectModels, subjectId); if (refSubjects == null || refSubjects.Count == 0) { return; } GameEntityModel refModel = refSubjects[StateManager.state.Random.NextInt(0, refSubjects.Count - 1)]; GameEntityAnchoringOperations.AnchorEntity(model, refModel, anchorId); }); }
// Build a single condition private static EventCondition <GameEntityModel> BuildFromParameter(Storage.GenericParameter parameter, out int keyFrame, Storage.CharacterAnimation animation) { keyFrame = InvalidKeyframe; EventCondition <GameEntityModel> .EvaluationDelegate evaluationDelegate; EventCondition <GameEntityModel> condition; int callIndex = parameter.type; int subjectId; if (callIndex < builderActions.Length) { evaluationDelegate = builderActions[callIndex](parameter, out keyFrame, animation); if (evaluationDelegate == null) { // No delegate, fixed keyFrame only return(null); } subjectId = GetSubjectId(parameter); return(new EventCondition <GameEntityModel>(evaluationDelegate, subjectId)); } Debug.Log("CharacterConditionsBuilder: Unknown condition type: " + parameter.type); return(null); }
// Global Variable private static EventCondition <GameEntityModel> .EvaluationDelegate BuildGlobalVariable(Storage.GenericParameter parameter, out int keyFrame, Storage.CharacterAnimation animation) { keyFrame = InvalidKeyframe; // Read var name, operator, numerator subject, numerator var, number, is timer string varName = parameter.SafeString(0); ConditionUtils <GameEntityModel> .ComparisonOperation comparisonOperator = (ConditionUtils <GameEntityModel> .ComparisonOperation)parameter.SafeInt(1); int numeratorSubjectId = parameter.SafeInt(2); string numeratorSubjectVarName = parameter.SafeString(1); int staticComparisonValue = parameter.SafeInt(3); // return delegate return(delegate(GameEntityModel mainModel, List <GameEntityModel>[] subjectModels){ int varValue = 0; WorldModel worldModel = StateManager.state.MainModel as WorldModel; worldModel.globalVariables.TryGetValue(varName, out varValue); return CompareWithNumerator(mainModel, numeratorSubjectId, numeratorSubjectVarName, varValue, staticComparisonValue, comparisonOperator, subjectModels); }); }
// Grounded private static EventCondition <GameEntityModel> .EvaluationDelegate BuildGrounded(Storage.GenericParameter parameter, out int keyFrame, Storage.CharacterAnimation animation) { keyFrame = InvalidKeyframe; // Read negation bool positiveCheck = !parameter.SafeBool(0); // Return delegate return(delegate(GameEntityModel mainModel, List <GameEntityModel>[] subjectModels){ PhysicPointModel pointModel; pointModel = StateManager.state.GetModel(mainModel.physicsModelId) as PhysicPointModel; if (pointModel == null) { return false; } return PhysicPointController.IsGrounded(pointModel) == positiveCheck; }); }
// Facing right private static EventCondition <GameEntityModel> .EvaluationDelegate BuildFacingRight(Storage.GenericParameter parameter, out int keyFrame, Storage.CharacterAnimation animation) { keyFrame = InvalidKeyframe; // Read negation bool positiveCheck = !parameter.SafeBool(0); // Return delegate return(delegate(GameEntityModel mainModel, List <GameEntityModel>[] subjectModels){ return mainModel.IsFacingRight() == positiveCheck; }); }
// Frame private static EventCondition <GameEntityModel> .EvaluationDelegate BuildFrame(Storage.GenericParameter parameter, out int keyFrame, Storage.CharacterAnimation animation) { keyFrame = InvalidKeyframe; // Read subject, operator, numerator subject, numerator variable, frame number int subjectId = parameter.SafeInt(0); ConditionUtils <GameEntityModel> .ComparisonOperation comparisonOperator = (ConditionUtils <GameEntityModel> .ComparisonOperation)parameter.SafeInt(1); int numeratorSubjectId = parameter.SafeInt(2); string numeratorSubjectVarName = parameter.SafeString(0); int staticComparisonFrame = parameter.SafeInt(3); // If it's equal to a static frame, no delegate required, return frame directly if (subjectId == (int)CharacterSubjectsBuilder.PredefinedSubjects.self && comparisonOperator == ConditionUtils <GameEntityModel> .ComparisonOperation.equal && numeratorSubjectId - 2 == (int)CharacterSubjectsBuilder.PredefinedSubjects.none ) { keyFrame = staticComparisonFrame; if (keyFrame < 0) { keyFrame = animation.numFrames - 1; } return(null); } // Else return delegate return(delegate(GameEntityModel mainModel, List <GameEntityModel>[] subjectModels){ AnimationModel animModel = StateManager.state.GetModel(mainModel.animationModelId) as AnimationModel; if (animModel == null) { return false; } return CompareWithNumerator(mainModel, numeratorSubjectId, numeratorSubjectVarName, (int)animModel.currentFrame, staticComparisonFrame, comparisonOperator, subjectModels); }); }
// Input Button private static EventCondition <GameEntityModel> .EvaluationDelegate BuildInputButton(Storage.GenericParameter parameter, out int keyFrame, Storage.CharacterAnimation animation) { keyFrame = InvalidKeyframe; // Read button, state, negation uint buttonId = (uint)parameter.SafeInt(1); ButtonState buttonState = (ButtonState)parameter.SafeInt(2); bool positiveCheck = !parameter.SafeBool(0); // Return delegate return(delegate(GameEntityModel mainModel, List <GameEntityModel>[] subjectModels){ PlayerInputModel inputModel = StateManager.state.GetModel(mainModel.inputModelId) as PlayerInputModel; if (inputModel == null) { return false; } PlayerInputController inputController = inputModel.Controller() as PlayerInputController; if (inputController == null) { return false; } bool verifies = false; // verify model's button state switch (buttonState) { case ButtonState.hold: verifies = inputController.IsButtonHold(inputModel, buttonId); break; case ButtonState.press: verifies = inputController.IsButtonPressed(inputModel, buttonId); break; case ButtonState.release: verifies = inputController.IsButtonReleased(inputModel, buttonId); break; } return verifies == positiveCheck; }); }
private static EventCondition <GameEntityModel> .EvaluationDelegate BuildAnimation(Storage.GenericParameter parameter, out int keyFrame, Storage.CharacterAnimation animation) { keyFrame = InvalidKeyframe; // Read anchor options, anchor IDs and if it's a single subject AnyOrAllOptions options = (AnyOrAllOptions)parameter.SafeInt(1); string[] names = parameter.SafeStringsList(0); return(delegate(GameEntityModel mainModel, List <GameEntityModel>[] subjectModels){ AnimationModel animModel = StateManager.state.GetModel(mainModel.animationModelId) as AnimationModel; bool anyOf = options == AnyOrAllOptions.anyOf; // "smart" loop here foreach (string name in names) { if (animModel.animationName == name) { return anyOf; } } return !anyOf; }); }
private static EventAction <GameEntityModel> .ExecutionDelegate BuildReleaseOwnership(Storage.GenericParameter parameter) { int subjectId = parameter.SafeInt(1); return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ List <GameEntityModel> subjectToBeReleased = ConditionUtils <GameEntityModel> .GetNonEmptySubjectOrNil(subjectModels, subjectId); if (subjectToBeReleased == null || subjectToBeReleased.Count == 0) { return; } foreach (GameEntityModel entityToBeReleased in subjectToBeReleased) { GameEntityAnchoringOperations.ReleaseOwnership(entityToBeReleased); } }); }
private static EventAction <GameEntityModel> .ExecutionDelegate BuildConsumeInput(Storage.GenericParameter parameter) { uint buttonId = (uint)parameter.SafeInt(1); bool consumeRelease = parameter.SafeBool(0); return(delegate(GameEntityModel mainModel, List <GameEntityModel>[] subjectModels){ PlayerInputModel inputModel = StateManager.state.GetModel(mainModel.inputModelId) as PlayerInputModel; if (inputModel == null) { return; } PlayerInputController inputController = inputModel.Controller() as PlayerInputController; if (inputController == null) { return; } if (consumeRelease) { inputController.ConsumeRelease(inputModel, buttonId); } else { inputController.ConsumePress(inputModel, buttonId); } }); }
private static EventAction <GameEntityModel> .ExecutionDelegate BuildSetAutoFlip(Storage.GenericParameter parameter) { bool autoValue = parameter.SafeBool(0); return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ GameEntityController.SetAutomaticFlip(model, autoValue); }); }
private static EventAction <GameEntityModel> .ExecutionDelegate BuildSetVariable(Storage.GenericParameter parameter) { string variableName = parameter.SafeString(0); int setMode = parameter.SafeInt(1); int numeratorSubjectId = parameter.SafeInt(2); string numeratorVariableName = parameter.SafeString(1); int defaultValue = parameter.SafeInt(3); FixedFloat percentage = (numeratorSubjectId == 0 || defaultValue == 0) ? 1 : ((FixedFloat)defaultValue) / 100; return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ int variableValue = GetNumeratorValue(model, numeratorSubjectId, numeratorVariableName, defaultValue, subjectModels); variableValue = (int)(variableValue * percentage); switch (setMode) { case 1: // add if (model.customVariables.ContainsKey(variableName)) { model.customVariables[variableName] += variableValue; } else { model.customVariables[variableName] = variableValue; } break; default: // set model.customVariables[variableName] = variableValue; break; } }); }
private static EventAction <GameEntityModel> .ExecutionDelegate BuildPausePhysics(Storage.GenericParameter parameter) { int numeratorSubjectId = parameter.SafeInt(1); string numeratorVariableName = parameter.SafeString(0); int defaultValue = parameter.SafeInt(2); FixedFloat percentage = (numeratorSubjectId == 0 || defaultValue == 0) ? 1 : ((FixedFloat)defaultValue) / 100; return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ int numeratorValue = GetNumeratorValue(model, numeratorSubjectId, numeratorVariableName, defaultValue, subjectModels); int pauseValue = (int)(numeratorValue * percentage); if (pauseValue > 0) { GameEntityController.PausePhysics(model, pauseValue); } }); }
private static EventAction <GameEntityModel> .ExecutionDelegate BuildDestroy(Storage.GenericParameter parameter) { return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ // TODO }); }
private static EventAction <GameEntityModel> .ExecutionDelegate BuildSpawnEffect(Storage.GenericParameter parameter) { FixedVector3 offset = BuildFixedVector3(parameter, 0); string prefabName = parameter.SafeString(0); int locationType = parameter.SafeInt(1); int localtionAnchorId = parameter.SafeInt(2); int facingOptions = parameter.SafeInt(3); bool localSpace = parameter.SafeBool(0); return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ // TODO }); }
private static EventAction <GameEntityModel> .ExecutionDelegate BuildSpawnEntity(Storage.GenericParameter parameter) { string entityName = parameter.SafeString(0); int locationType = parameter.SafeInt(1); int localtionAnchorId = parameter.SafeInt(2); string initialAnimation = parameter.SafeString(1); int teamId = parameter.SafeInt(3); bool own = parameter.SafeBool(0); string[] variableNames = parameter.SafeStringsList(0); int[] variableValues = parameter.SafeIntsList(0); // what if using referenced values from something else?, [energy] etc int facingOptions = parameter.SafeInt(4); FixedVector3 offset = BuildFixedVector3(parameter, 0); return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ // TODO }); }
// Velocity private static EventCondition <GameEntityModel> .EvaluationDelegate BuildVelocity(Storage.GenericParameter parameter, out int keyFrame, Storage.CharacterAnimation animation) { keyFrame = InvalidKeyframe; // Read orientation, operator, numerator subject, numerator var, number, module Orientation orientation = (Orientation)parameter.SafeInt(1); ConditionUtils <GameEntityModel> .ComparisonOperation comparisonOperator = (ConditionUtils <GameEntityModel> .ComparisonOperation)parameter.SafeInt(2); int numeratorSubjectId = parameter.SafeInt(3); string numeratorSubjectVarName = parameter.SafeString(0); FixedFloat staticComparisonValue = parameter.SafeFloat(0); bool useModule = parameter.SafeBool(1); // return delegate return(delegate(GameEntityModel mainModel, List <GameEntityModel>[] subjectModels){ PhysicPointModel pointModel = StateManager.state.GetModel(mainModel.physicsModelId) as PhysicPointModel; if (pointModel == null) { return false; } FixedFloat velocityValue = getOrientedAxisValue(pointModel.GetVelocity(), orientation, useModule); return CompareWithNumerator(mainModel, numeratorSubjectId, numeratorSubjectVarName, velocityValue, staticComparisonValue, comparisonOperator, subjectModels); }); }
private static EventAction <GameEntityModel> .ExecutionDelegate BuildReleaseGrab(Storage.GenericParameter parameter) { int subjectId = parameter.SafeInt(1); return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ List <GameEntityModel> refSubjects = ConditionUtils <GameEntityModel> .GetNonEmptySubjectOrNil(subjectModels, subjectId); if (refSubjects == null || refSubjects.Count == 0) { return; } foreach (GameEntityModel refSubject in refSubjects) { GameEntityAnchoringOperations.ReleaseAnchoredEntity(model, refSubject); } }); }
private static EventCondition <GameEntityModel> .EvaluationDelegate BuildExistence(Storage.GenericParameter parameter, out int keyFrame, Storage.CharacterAnimation animation) { keyFrame = InvalidKeyframe; // Read target subject, negation int targerSubjectId = parameter.SafeInt(1); bool positiveCheck = !parameter.SafeBool(0); // Return delegate return(delegate(GameEntityModel mainModel, List <GameEntityModel>[] subjectModels){ bool exists = subjectModels[targerSubjectId] != null && subjectModels[targerSubjectId].Count > 0; return exists == positiveCheck; }); }
// Get subjectId from parameter private static int GetSubjectId(Storage.GenericParameter parameter) { return(parameter.SafeInt(0)); }
// frame = 4 private static HitData BuildStandardHit(Storage.GenericParameter parameter) { return(new HitData((HitData.HitType)parameter.SafeInt(0), parameter.SafeInt(1), (HitData.HitFacing)parameter.SafeInt(2))); }
private static EventAction <GameEntityModel> .ExecutionDelegate BuildSetGlobalVariable(Storage.GenericParameter parameter) { string variableName = parameter.SafeString(0); int setMode = parameter.SafeInt(1); int numeratorSubjectId = parameter.SafeInt(2); string numeratorVariableName = parameter.SafeString(1); int defaultValue = parameter.SafeInt(3); FixedFloat percentage = (numeratorSubjectId == 0 || defaultValue == 0) ? 1 : ((FixedFloat)defaultValue) / 100; return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ int variableValue = GetNumeratorValue(model, numeratorSubjectId, numeratorVariableName, defaultValue, subjectModels); variableValue = (int)(variableValue * percentage); // Global variable may have references to a team ID, character name, player number, etc numeratorVariableName = CharacterConditionsBuilder.ParseVariableValuesInGlobalName(model, numeratorVariableName); WorldModel worldModel = StateManager.state.MainModel as WorldModel; switch (setMode) { case 1: // add if (worldModel.globalVariables.ContainsKey(variableName)) { worldModel.globalVariables[variableName] += variableValue; } else { worldModel.globalVariables[variableName] = variableValue; } break; default: // set worldModel.globalVariables[variableName] = variableValue; break; } }); }