예제 #1
0
        private static List <GameEntityModel> CreateSubjectsWithSubject(GameEntityModel subject)
        {
            List <GameEntityModel> subjects = new List <GameEntityModel>(1);

            subjects.Add(subject);
            return(subjects);
        }
예제 #2
0
        public static GameObject GetCharacterShadow(GameEntityModel model, GameObject root)
        {
            Storage.Character storageCharacter;
            AnimationModel    animModel = StateManager.state.GetModel(model.animationModelId) as AnimationModel;

            if (animModel == null)
            {
                return(null);
            }
            if (!loadedCharacters.TryGetValue(animModel.characterName, out storageCharacter))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(storageCharacter.shadowName))
            {
                return(null);
            }
            Transform shadow = root.transform.FindChild(storageCharacter.shadowName);

            if (shadow == null || shadow == root.transform)
            {
                return(null);
            }
            return(shadow.gameObject);
        }
예제 #3
0
		// Get freedom from owner entity
		public static void ReleaseOwnership(GameEntityModel model){
			if (model.ownerEntity != null && model.ownerEntity != ModelReference.InvalidModelIndex) {
				GameEntityModel owner = StateManager.state.GetModel(model.ownerEntity) as GameEntityModel;
				owner.ownedEntities.Remove(model.Index);
				model.ownerEntity = new ModelReference(ModelReference.InvalidModelIndex);
			}
		}
예제 #4
0
		// Set anchored entity position relatively to it's parent
		public static void SetAnchoredEntityRelativePosition(GameEntityModel model, int anchorId, FixedVector3 relativePosition){
			if (model.anchoredEntities == null || model.anchoredEntities.Count <= anchorId) return;
			GameEntityModel anchoredEntityModel = StateManager.state.GetModel(model.anchoredEntities[anchorId]) as GameEntityModel;
			if (anchoredEntityModel != null){
				anchoredEntityModel.positionRelativeToParent = relativePosition;
			}
		}
예제 #5
0
        // Filter hit by hitter entity location
        private static GameEntityModel getHitEntityIfConformingOrientationOptions(HitInformation hit, OrientationOptions orientationOptions, GameEntityModel model)
        {
            GameEntityModel hitterModel = StateManager.state.GetModel(hit.entityId) as GameEntityModel;

            if (orientationOptions == OrientationOptions.any)
            {
                return(hitterModel);
            }

            PhysicPointModel modelPoint  = GameEntityController.GetPointModel(model);
            PhysicPointModel hitterPoint = GameEntityController.GetPointModel(hitterModel);
            bool             isFrontal;

            if (model.IsFacingRight())
            {
                isFrontal = hitterPoint.position.X >= modelPoint.position.X;
            }
            else
            {
                isFrontal = hitterPoint.position.X <= modelPoint.position.X;
            }
            if (isFrontal == (orientationOptions == OrientationOptions.fromFront))
            {
                return(hitterModel);
            }
            return(null);
        }
예제 #6
0
		// Parent name (who's anchoring the entity)
		public static string ParentEntityName(GameEntityModel model){
			GameEntityModel parentEntityModel = StateManager.state.GetModel(model.parentEntity) as GameEntityModel;
			if (parentEntityModel == null) return null;
			AnimationModel animModel = GameEntityController.GetAnimationModel(parentEntityModel);
			if (animModel == null) return null;
			return animModel.characterName;
		}
예제 #7
0
		// Anchor a model to it
		public static void AnchorEntity(GameEntityModel model, GameEntityModel modelToBeAnchored, int anchorId){
			if (IsAnchored(modelToBeAnchored)){
				Debug.LogWarning("Trying to anchor an entity that is already anchored");
				return;
			}
			if (model.parentEntity != null && model.parentEntity == modelToBeAnchored.Index){
				Debug.LogWarning("Cyclic anchoring attempt");
				return;
			}
			if (model.anchoredEntities == null) model.anchoredEntities = new List<ModelReference>(anchorId);
			while (model.anchoredEntities.Count <= anchorId) {
				model.anchoredEntities.Add(null);
			}
			if (model.anchoredEntities[anchorId] != null && model.anchoredEntities[anchorId] != ModelReference.InvalidModelIndex){
				Debug.LogWarning("Trying to anchor an entity to a busy anchor");
				return;
			}
			model.anchoredEntities[anchorId] = modelToBeAnchored.Index;
			modelToBeAnchored.parentEntity = model.Index;
			modelToBeAnchored.positionRelativeToParent = FixedVector3.Zero;
			PhysicPointModel pointModel = GameEntityController.GetPointModel(modelToBeAnchored);
			if (pointModel != null){
				pointModel.isActive = false;
			}
		}
예제 #8
0
 // Process general animation events
 private void ProcessGeneralEvents(AnimationModel model, GameEntityModel entityModel)
 {
     foreach (ConditionalEvent <GameEntityModel> e in generalEvents)
     {
         e.Evaluate(entityModel);
     }
 }
예제 #9
0
		// Release event may be accompained by a set animation event and set anchored position.
		// It safely releases at the relative position to parent, taking physics in consideration
		public static void ReleaseAnchoredEntity(GameEntityModel model, GameEntityModel anchoredEntityModel){
			int anchorId = -1;
			for (int i = 0; i < model.anchoredEntities.Count ; ++i){
				if (model.anchoredEntities[i] == anchoredEntityModel.Index){
					anchorId = i;
					break;
				}
			}
			if (anchorId == -1){
				// entity is not grabbed, return
				return;
			}
			anchoredEntityModel.parentEntity = new ModelReference();
			PhysicPointModel pointModel = GameEntityController.GetPointModel(anchoredEntityModel);
			if (pointModel != null){
				pointModel.isActive = true;
				PhysicPointModel parentPointModel = GameEntityController.GetPointModel(model);
				PhysicPointController pointController = pointModel.Controller() as PhysicPointController;
				if (pointController != null && parentPointModel != null){
					// Set position directly
					pointModel.position = parentPointModel.position;
					if (!model.IsFacingRight()) anchoredEntityModel.positionRelativeToParent.X *= -1;
					pointController.SetVelocityAffector(pointModel, PhysicPointController.setPositionffectorName, anchoredEntityModel.positionRelativeToParent);
					anchoredEntityModel.positionRelativeToParent = FixedVector3.Zero;
				}
			}
			model.anchoredEntities[anchorId] = new ModelReference();
		}
예제 #10
0
		// Anchored animation name
		public static string AnchoredEntityAnimation(GameEntityModel model, int anchorId){
			if (model.anchoredEntities == null || model.anchoredEntities.Count <= anchorId || model.anchoredEntities[anchorId] == null) return null;
			GameEntityModel anchoredEntityModel = StateManager.state.GetModel(model.anchoredEntities[anchorId]) as GameEntityModel;
			if (anchoredEntityModel == null) return null;
			AnimationModel animModel = GameEntityController.GetAnimationModel(anchoredEntityModel);
			if (animModel == null) return null;
			return animModel.animationName;
		}
 public static bool IsFacingRight(this GameEntityModel model)
 {
     if (model.parentEntity != null && model.parentEntity != ModelReference.InvalidModelIndex)
     {
         GameEntityModel parentModel = StateManager.state.GetModel(model.parentEntity) as GameEntityModel;
         return(parentModel.mIsFacingRight);
     }
     return(model.mIsFacingRight);
 }
예제 #12
0
        public static bool IsHittingFarWall(GameEntityModel model)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return(false);
            }
            return(pointModel.collisionInpact.Z > 0);
        }
예제 #13
0
        // ----------------------
        // Ground and Wall checks

        public static bool IsGrounded(GameEntityModel model)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return(false);
            }
            return(PhysicPointController.IsGrounded(pointModel));
        }
예제 #14
0
        // Find any entity interacting with the one from the required team, except if it matches the given exception reference
        public static GameEntityModel GetInteractionEntityWithEntityFromTeam(int teamId, int playerNumber, ModelReference exception)
        {
            GameEntityModel originalEntity = GetEntityFromTeam(teamId, playerNumber);

            if (originalEntity == null)
            {
                return(null);
            }
            return(GetInteractionEntity(originalEntity, exception));
        }
예제 #15
0
        // Apply a force on the physics velocity affector
        public static FixedFloat GetVerticalImpulse(GameEntityModel model)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return(FixedFloat.Zero);
            }
            return(pointModel.velocityAffectors[PhysicPointModel.defaultVelocityAffectorName].Y);
        }
예제 #16
0
        public static FixedFloat CollisionZForce(GameEntityModel model)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return(FixedFloat.Zero);
            }
            return(FixedFloat.Abs(pointModel.collisionInpact.Z));
        }
예제 #17
0
        // 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);
                }
            }));
        }
예제 #18
0
		// Forces the animation of an anchored entity, so that it can't be messed with it's current animation events
		public static void SetAnchoredEntityAnimation(GameEntityModel model, int anchorId, string animationName){
			if (model.anchoredEntities == null || model.anchoredEntities.Count <= anchorId) return;
			GameEntityModel anchoredEntityModel = StateManager.state.GetModel(model.anchoredEntities[anchorId]) as GameEntityModel;
			if (anchoredEntityModel != null){
				AnimationModel anchoredAnimationModel = GameEntityController.GetAnimationModel(anchoredEntityModel);
				AnimationController anchoredAnimController = anchoredAnimationModel.Controller() as AnimationController;
				if (anchoredAnimController != null){
					// Force animation, so that it ignores any desired transition from a previous animation update 
					anchoredAnimController.ForceAnimation(anchoredAnimationModel, animationName);
				}
			}
		}
예제 #19
0
        // 2: GetOwnerOrSelf
        private static EventSubject <GameEntityModel> .GetSubjectsDelegate GetOwnerOrSelf(Storage.GenericParameter parameter)
        {
            int subjectId = parameter.SafeInt(0);

            return(DefaultDelegation(subjectId, delegate(GameEntityModel model, List <GameEntityModel> subjects){
                GameEntityModel ownerOrSelfModel = StateManager.state.GetModel(model.ownerEntity) as GameEntityModel;
                if (ownerOrSelfModel == null)
                {
                    ownerOrSelfModel = model;
                }
                subjects.Add(ownerOrSelfModel);
            }));
        }
예제 #20
0
        // 7: GetColliding
        private static EventSubject <GameEntityModel> .GetSubjectsDelegate GetColliding(Storage.GenericParameter parameter)
        {
            int subjectId = parameter.SafeInt(0);

            return(DefaultDelegation(subjectId, delegate(GameEntityModel model, List <GameEntityModel> subjects){
                GameEntityController controller = model.Controller() as GameEntityController;
                if (controller.lastCollisionEntityId != null && controller.lastCollisionEntityId != ModelReference.InvalidModelIndex)
                {
                    GameEntityModel collidingEntity = StateManager.state.GetModel(controller.lastCollisionEntityId) as GameEntityModel;
                    subjects.Add(collidingEntity);
                }
            }));
        }
예제 #21
0
		// Anchor a model to it, and optionally move the parent relative to the entity being anchored (e.g. move back a little when grabbing)
		public static void AnchorEntity(GameEntityModel model, GameEntityModel modelToBeAnchored, int anchorId, FixedVector3 deltaPosRelativeToAnched){
			AnchorEntity(model, modelToBeAnchored, anchorId);
			PhysicPointModel pointModel = GameEntityController.GetPointModel(model);
			PhysicPointModel anchoredPointModel = GameEntityController.GetPointModel(modelToBeAnchored);
			if (pointModel != null && anchoredPointModel != null){
				PhysicPointController pointController = pointModel.Controller() as PhysicPointController;
				if (pointController != null){
					if (!model.IsFacingRight()) deltaPosRelativeToAnched.X *= -1;
					FixedVector3 deltaPos = (anchoredPointModel.position + deltaPosRelativeToAnched) - pointModel.position;
					pointController.SetVelocityAffector(pointModel, PhysicPointController.setPositionffectorName, deltaPos);
				}
			}
		}
예제 #22
0
        // Safelly set position relative to self (e.g. vault), taking physics collisions in consideration
        public static void MoveEntity(GameEntityModel model, FixedVector3 relativePosition)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel != null)
            {
                PhysicPointController pointController = pointModel.Controller() as PhysicPointController;
                if (pointController != null)
                {
                    pointController.SetVelocityAffector(pointModel, PhysicPointController.setPositionffectorName, relativePosition);
                }
            }
        }
예제 #23
0
        // On post-update we move to next frame, if animation didn't change
        protected override void PostUpdate(AnimationModel model)
        {
            GameEntityModel entityModel = StateManager.state.GetModel(model.ownerId) as GameEntityModel;

            if (entityModel != null && entityModel.pauseTimer > 0)
            {
                return;
            }

            bool haveNewNextFrame = model.nextFrame != AnimationModel.invalidFrameId;
            bool haveNewAnimation = model.nextAnimation != null && model.nextAnimation != model.animationName;

            if (haveNewNextFrame)
            {
                model.currentFrame = (uint)model.nextFrame;
            }

            if (haveNewAnimation)
            {
                model.animationName = model.nextAnimation;
                // clear hitten entities
                model.hittenEntitiesByHitId = null;
                GameEntityModel anchoredModel;
                AnimationModel  anchoredAnimationModel;
                foreach (ModelReference anchoredRef in entityModel.anchoredEntities)
                {
                    if (anchoredRef != null && anchoredRef != ModelReference.InvalidModelIndex)
                    {
                        anchoredModel = StateManager.state.GetModel(anchoredRef) as GameEntityModel;
                        if (anchoredModel == null)
                        {
                            continue;
                        }
                        anchoredAnimationModel = StateManager.state.GetModel(anchoredModel.animationModelId) as AnimationModel;
                        if (anchoredAnimationModel == null)
                        {
                            continue;
                        }
                        anchoredAnimationModel.hittenEntitiesByHitId = null;
                    }
                }
                model.InvalidateVC();
            }

            if (!haveNewNextFrame && !haveNewAnimation)
            {
                // move to next frame
                ++model.currentFrame;
            }
        }
예제 #24
0
 // Process any events for this keyframe
 private void ProcessKeyframeEvents(AnimationModel model, GameEntityModel entityModel)
 {
     if (keyframeEvents != null)
     {
         List <ConditionalEvent <GameEntityModel> > currentFrameEvents;
         if (keyframeEvents.TryGetValue(model.currentFrame, out currentFrameEvents))
         {
             foreach (ConditionalEvent <GameEntityModel> e in currentFrameEvents)
             {
                 e.Evaluate(entityModel);
             }
         }
     }
 }
        // 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);
        }
예제 #26
0
        // Set the velocity affector bound to animation velocity control
        public static void SetAnimationVelocity(GameEntityModel model, FixedVector3 velocity)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return;
            }
            if (!model.IsFacingRight())
            {
                velocity.X *= -1;
            }
            pointModel.velocityAffectors[GameEntityController.animVelocityAffector] = velocity;
        }
예제 #27
0
        // Reset X and Z force components on the physics velocity affector
        public static void ResetPlanarImpulse(GameEntityModel model)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return;
            }
            FixedVector3 originalImpulse;

            pointModel.velocityAffectors.TryGetValue(PhysicPointModel.defaultVelocityAffectorName, out originalImpulse);
            pointModel.velocityAffectors[PhysicPointModel.defaultVelocityAffectorName] =
                new FixedVector3(0, originalImpulse.Y, 0)
            ;
        }
예제 #28
0
        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);
            });
        }
        // TODO: move to somwhere handling global variables
        public static string ParseVariableValuesInGlobalName(GameEntityModel model, string text)
        {
            GroupCollection groups = Regex.Match(text, @"\[(.*?)\]").Groups;
            int             variableValue;
            string          resultingText = text;

            foreach (Group g in groups)
            {
                if (!TryGetVariableValue(model, g.Value, out variableValue))
                {
                    variableValue = 0;
                }
                resultingText.Replace(g.Value, variableValue + "");
            }
            return(resultingText);
        }
예제 #30
0
        // Apply a force on the physics velocity affector
        public static void AddImpulse(GameEntityModel model, FixedVector3 impulse)
        {
            PhysicPointModel pointModel = GameEntityController.GetPointModel(model);

            if (pointModel == null)
            {
                return;
            }
            if (!model.IsFacingRight())
            {
                impulse.X *= -1;
            }
            pointModel.velocityAffectors[PhysicPointModel.defaultVelocityAffectorName] += impulse;
            //			pointModel.velocityAffectors[PhysicPointModel.defaultVelocityAffectorName] += new FixedVector3(0, impulse.Y, 0);
            //			pointModel.velocityAffectors[GameEntityController.animVelocityAffector] += new FixedVector3(impulse.X, 0, impulse.Z);
        }