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; } }); }
// CompareWithNumerator, FixedFloat version private static bool CompareWithNumerator( GameEntityModel mainModel, int numeratorSubjectId, string numeratorSubjectVarName, FixedFloat comparisonValue, FixedFloat staticComparisonValue, ConditionUtils <GameEntityModel> .ComparisonOperation comparisonOperator, List <GameEntityModel>[] subjectModels ) { // no subject if (numeratorSubjectId == 0) { return(ConditionUtils <GameEntityModel> .Compare(comparisonOperator, comparisonValue, staticComparisonValue)); } // global variable if (numeratorSubjectId == 1) { // Global variable may have references to a team ID, character name, player number, etc numeratorSubjectVarName = ParseVariableValuesInGlobalName(mainModel, numeratorSubjectVarName); int globalVariableValue = 0; WorldModel worldModel = StateManager.state.MainModel as WorldModel; worldModel.globalVariables.TryGetValue(numeratorSubjectVarName, out globalVariableValue); return(ConditionUtils <GameEntityModel> .Compare(comparisonOperator, comparisonValue, (FixedFloat)globalVariableValue)); } // subject variable numeratorSubjectId -= 2; List <GameEntityModel> comparisonSubject = ConditionUtils <GameEntityModel> .GetNonEmptySubjectOrNil(subjectModels, numeratorSubjectId); if (comparisonSubject == null || comparisonSubject.Count == 0) { return(false); } // compare each model's velocity with each comparison subject variable, return true if all pass int variableValue; foreach (GameEntityModel comparisonModel in comparisonSubject) { if (!comparisonModel.customVariables.TryGetValue(numeratorSubjectVarName, out variableValue)) { return(false); } if (!ConditionUtils <GameEntityModel> .Compare(comparisonOperator, comparisonValue, (FixedFloat)variableValue)) { return(false); } } return(true); }
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); }); }
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 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); } }); }
// pos(2.1, 4.2, 5.3) private static EventAction <GameEntityModel> .ExecutionDelegate BuildSetDeltaPosition(Storage.GenericParameter parameter) { int relativeSubjectId = parameter.SafeInt(1); FixedVector3 deltaPos = BuildFixedVector3(parameter, 0); return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){ List <GameEntityModel> refSubjects = ConditionUtils <GameEntityModel> .GetNonEmptySubjectOrNil(subjectModels, relativeSubjectId); if (refSubjects == null || refSubjects.Count == 0) { return; } // Select one randomly GameEntityModel refModel = refSubjects[StateManager.state.Random.NextInt(0, refSubjects.Count - 1)]; FixedVector3 realDelta; if (!refModel.IsFacingRight()) { deltaPos.X *= -1; } PhysicPointModel mainPoint = StateManager.state.GetModel(model.physicsModelId) as PhysicPointModel; if (mainPoint == null) { return; } if (refModel != model) { PhysicPointModel refPoint = StateManager.state.GetModel(refModel.physicsModelId) as PhysicPointModel; if (refPoint == null) { return; } realDelta = (refPoint.position + deltaPos) - mainPoint.position; } else { realDelta = deltaPos; } PhysicPointController pointController = mainPoint.Controller() as PhysicPointController; if (pointController == null) { return; } pointController.SetVelocityAffector(mainPoint, PhysicPointController.setPositionffectorName, realDelta); }); }
// private static GenericEvent<GameEntityModel> BuildSpawnEffect(Storage.GenericParameter parameter){ // FixedVector3 offset = BuildFixedVector3(parameter); // string prefabName = parameter.SafeString(0); // int locationType = parameter.SafeInt(0); // int lifetime = parameter.SafeInt(1); // bool localSpace = parameter.SafeBool(0); // // // {"self", "anchor", "hit intersection", "hurt intersection"} // PentaEntityAnimationEvent<string, int, FixedVector3, bool, GameEntityView.ConvertGameToViewCoordinates>.EventExecutionDelegate theDelegate = null; // switch (locationType) { // case 0: // // self // theDelegate = GameEntityView.SpawnAtSelf; // break; // case 1: // // Anchor, TODO: which anchor? // RetroBread.Debug.LogError("Spawn at anchor not supported yet"); // break; // case 2: // // hit // theDelegate = GameEntityView.SpawnAtHitIntersection; // break; // case 3: // // hurt // theDelegate = GameEntityView.SpawnAtHurtIntersection; // break; // } // // return new PentaEntityAnimationEvent<string, int, FixedVector3, bool, GameEntityView.ConvertGameToViewCoordinates>( // null, // theDelegate, // prefabName, // lifetime, // offset, // localSpace, // PhysicPoint2DView.ConvertGameToViewCoordinates // TODO: store this delegate at a setup file, so it's easier to configure // ); // // } #endregion #region Auxiliar Functions // CompareWithNumerator, int version // Comes in duplicate due to conversion FixedFloat to int not working with parameterized types // TODO; extract this method to some utils, as it's used by CharacterConditionsBuilder, adapted private static int GetNumeratorValue( GameEntityModel mainModel, int numeratorSubjectId, string numeratorSubjectVarName, int staticValue, List <GameEntityModel>[] subjectModels ) { // no subject if (numeratorSubjectId == 0) { return(staticValue); } // global variable if (numeratorSubjectId == 1) { // Global variable may have references to a team ID, character name, player number, etc numeratorSubjectVarName = CharacterConditionsBuilder.ParseVariableValuesInGlobalName(mainModel, numeratorSubjectVarName); int globalVariableValue = 0; WorldModel worldModel = StateManager.state.MainModel as WorldModel; worldModel.globalVariables.TryGetValue(numeratorSubjectVarName, out globalVariableValue); return(globalVariableValue); } // subject variable numeratorSubjectId -= 2; List <GameEntityModel> numeratorSubjects = ConditionUtils <GameEntityModel> .GetNonEmptySubjectOrNil(subjectModels, numeratorSubjectId); if (numeratorSubjects == null || numeratorSubjects.Count == 0) { return(0); } // need only one value int variableValue; foreach (GameEntityModel comparisonModel in numeratorSubjects) { if (CharacterConditionsBuilder.TryGetVariableValue(comparisonModel, numeratorSubjectVarName, out variableValue)) { return(variableValue); } } return(0); }