コード例 #1
0
        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;
                }
            });
        }
コード例 #2
0
        private static ConditionalEvent <GameEntityModel> ReadEvent(Storage.Character charData, Storage.GenericEvent storageEvent, out int keyFrame, Storage.CharacterAnimation animation)
        {
            // Build event
            List <EventSubject <GameEntityModel> >   subjects;
            List <EventCondition <GameEntityModel> > conditions;
            List <EventAction <GameEntityModel> >    actions;

            subjects   = CharacterSubjectsBuilder.Build(charData, storageEvent.subjectIds);
            conditions = CharacterConditionsBuilder.Build(charData, storageEvent.conditionIds, out keyFrame, animation);
            actions    = CharacterActionsBuilder.Build(charData, storageEvent.eventIds);
            return(new ConditionalEvent <GameEntityModel>(subjects, conditions, actions));
        }
コード例 #3
0
//		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);
        }