Advertisement
Guest User

Untitled

a guest
Jan 16th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /////////////////////////////////////
  2. class KHRWeapon extends UDKWeapon;
  3.  
  4. var byte InventoryGroup;        // Grupo de inventario. Se usa para cambiar de arma
  5.  
  6. // ****************************************************************
  7. // Instant HIT
  8. // ****************************************************************
  9. var ParticleSystem BeamTemplate;    // Sistema de partículas del rayo mostrado en Instant Hit
  10.  
  11. var MaterialInterface ExplosionDecal;       // Decal (calcomanía) que deja en las superficies el Instant Hit
  12. var float DecalWidth, DecalHeight;          // Ancho y altura del decal
  13. var float DurationOfDecal;                  // Duraci del decal antes de desaparecer
  14. var name DecalDissolveParamName;            // Nombre del par疥etro del MaterialInstance para disolver el material
  15. var bool HiddenKey;
  16. var int AttackValue;
  17. var int MagicValue;
  18.  
  19. // ****************************************************************
  20. // Animation Variables
  21. // ****************************************************************
  22.  
  23. var array <Name> SwingAnimations;         // Nombres de las animaciones a usar
  24. var array <float> SwingIntervals;         // Intervalos de tiempo de cada animacion
  25. var int currentSwing;                    // Animacion actual
  26.  
  27. var SoundCue SwingSound;                // Sonido de espadazo
  28.  
  29. // ****************************************************************
  30. // Weapon Location
  31. // ****************************************************************
  32. // Determina la posici real del arma
  33. simulated event SetPosition(UDKPawn Holder)
  34. {
  35.     local SkeletalMeshComponent weaponMesh;
  36.     local SkeletalMeshSocket socket;
  37.     local Vector FinalLocation;
  38.  
  39.     weaponMesh = Holder.Mesh;
  40.  
  41.     if (weaponMesh != none)
  42.     {
  43.         socket = weaponMesh.GetSocketByName('RightWeapon');
  44.         if (socket != none)
  45.         {
  46.             FinalLocation = weaponMesh.GetBoneLocation(socket.BoneName);
  47.         }
  48.     }
  49.     SetLocation(FinalLocation);
  50. }
  51.  
  52. // Calcula la posici real desde donde se disparan los proyectiles
  53. simulated event vector GetPhysicalFireStartLoc(optional vector AimDir)
  54. {
  55.     local SkeletalMeshComponent weaponMesh;
  56.     local SkeletalMeshSocket socket;
  57.  
  58.     weaponMesh = Instigator.Mesh;
  59.  
  60.     if (weaponMesh != none)
  61.     {
  62.         socket = weaponMesh.GetSocketByName('RightWeapon');
  63.         if (socket != none)
  64.         {
  65.              return weaponMesh.GetBoneLocation(socket.BoneName);
  66.         }
  67.     }
  68. }
  69.  
  70. // Sobreescribe la funcion de Weapon. Procesa los impactos instantaneos.
  71. simulated function ProcessInstantHit(byte FiringMode, ImpactInfo Impact, optional int NumHits)
  72. {
  73.     local MaterialInstanceTimeVarying MITV_Decal;
  74.  
  75.     // Calcula el da total y lo aplica al actor
  76.     Super.ProcessInstantHit(FiringMode, Impact, NumHits);
  77.  
  78.     // Creaci del Decal
  79.     MITV_Decal = new(self) class'MaterialInstanceTimeVarying';
  80.     MITV_Decal.SetParent(ExplosionDecal);
  81.     WorldInfo.MyDecalManager.SpawnDecal(MITV_Decal, Impact.HitLocation, rotator(-Impact.HitNormal), DecalWidth, DecalHeight, 10.0, FALSE );
  82.     MITV_Decal.SetScalarStartTime( DecalDissolveParamName, DurationOfDecal );
  83. }
  84.  
  85. // Se llama al equipar el arma
  86. simulated function TimeWeaponEquipping()
  87. {
  88.     AttachWeaponTo( Instigator.Mesh,'RightWeapon' );
  89.     super.TimeWeaponEquipping();
  90. }
  91.  
  92. // Acopla el arma a la malla del pawn
  93. simulated function AttachWeaponTo( SkeletalMeshComponent MeshComp, optional Name SocketName )
  94. {
  95.     MeshComp.AttachComponentToSocket(Mesh,SocketName);
  96.     Mesh.SetLightEnvironment(KHRPawn(Instigator).LightEnvironment);
  97. }
  98.  
  99. // Llamado al dejar de usar el arma
  100. simulated function DetachWeapon()
  101. {
  102.     Instigator.Mesh.DetachComponent(Mesh);
  103.     SetBase(None);
  104.     SetHidden(True);
  105.     HiddenKey = !HiddenKey;
  106.    
  107.     if(HiddenKey == false)
  108.     {
  109.    
  110.     }
  111.     else
  112.     {
  113.    
  114.     }
  115. }
  116.  
  117.  
  118. // ****************************************************************
  119. // Weapon Animation
  120. // ****************************************************************
  121.  
  122. // Se sobreescribe para evitar que al soltar el boton se desactive cualquier ataque
  123. simulated function StopFire(byte FireModeNum);
  124.  
  125.  
  126.  
  127. // Disparo efectivo
  128. simulated function FireAmmunition()
  129. {
  130.  // Se declara que el ataque se ha cumplido
  131.  Super.StopFire(CurrentFireMode);
  132.  
  133.  // Se elimina posible Timer de reseteo del sistema de melee
  134.  ClearTimer(nameof(ResetMelee));
  135.  
  136.  // Animacion de melee (AnimName, Rate, BlendInTime, BlendOutTime, bLooping, bOverride)
  137.  KHRPawn(Owner).MeleeAnimNode.PlayCustomAnim(SwingAnimations[currentSwing], 1.0,0.05,0.1,false,true);
  138.  
  139.  // Efectos
  140.  SpawnSwingEffects();
  141.  
  142.  // Se reprograma el intervalo de RefireCheckTimer adecuadamente
  143.  FireInterval[0] = SwingIntervals[currentSwing];
  144.  TimeWeaponFiring(CurrentFireMode);
  145.  
  146.  // Aumenta el indice de las animaciones para pasar a la siguiente
  147.  currentSwing = (currentSwing + 1) % SwingAnimations.length;
  148.  
  149.  // Se desactiva el desplazamiento del Pawn
  150.  KHRPlayerController(Pawn(Owner).Controller).SetRotationOnly(true);
  151.  
  152.  Super.FireAmmunition();
  153. }
  154.  
  155.  
  156.  
  157. // Programa un timer para llamar a RefireCheckTimer
  158. simulated function TimeWeaponFiring( byte FireModeNum )
  159. {
  160.  // Si desde que se inicio el ataque anterior se ha pulsado otra vez clic, RefireCheckTimer volvera a
  161.  // lanzar un ataque, pues PendingFire sera = 1
  162.  SetTimer( GetFireInterval(FireModeNum), false, nameof(RefireCheckTimer) );
  163. }
  164.  
  165.  
  166. // Llamado al desactivar este arma
  167. simulated function PutDownWeapon()
  168. {
  169.     HandleFinishedFiring();
  170.     Super.PutDownWeapon();
  171. }
  172.  
  173. // Llamado cuando se deja de "disparar". Se llama si RefireCheckTimer determina que no hay que seguir atacando.
  174. simulated function HandleFinishedFiring()
  175. {
  176.     if (KHRPawn(Owner).MeleeAnimNode.GetCustomAnimNodeSeq() != None)
  177.     { // Se activa un Timer que reseteara el sistema de Melee cuando termine la animacion actual
  178.         SetTimer(KHRPawn(Owner).MeleeAnimNode.GetCustomAnimNodeSeq().GetTimeLeft(), false, nameof(ResetMelee));
  179.     }
  180.  
  181.     // Se reactiva el movimiento del Pawn
  182.     KHRPlayerController(Pawn(Owner).Controller).SetRotationOnly(false);
  183.  
  184.     Super.HandleFinishedFiring();
  185. }
  186.  
  187. // Se llama cuando la animacion de melee concluye. Resetea el sistema para que las animaciones comiencen desde la primera.
  188. function ResetMelee()
  189. {
  190.     // Se resetea el combo
  191.     currentSwing = 0;
  192. }
  193.  
  194. // Efectos de ataque
  195. function SpawnSwingEffects()
  196. {
  197.     // Sonido de impacto
  198.     if (SwingSound != None)
  199.     {
  200.         PlaySound(SwingSound, true);
  201.     }
  202. }
  203.  
  204.  
  205.  
  206. ////////////////////////////////////////////////////////
  207. ////////////////////////////////////////////////////////
  208. ////////////////////////////////////////////////////////
  209.  
  210. class KHRPawn extends Pawn;
  211.  
  212. /******************************************************************************
  213. Player Properties
  214. ******************************************************************************/
  215. var() int HP;
  216. var() int totalHP;
  217. var() int MP;
  218. var() int totalMP;
  219. var DynamicLightEnvironmentComponent LightEnvironment;
  220.  
  221.  
  222. /******************************************************************************
  223. Camera Properties
  224. ******************************************************************************/
  225. var float CameraScale;          // Multiplicador de la distancia por defecto
  226. var float CurrentCameraScale;   // Se usa para interpolar entre distintos CameraScales
  227. var float CameraZOffset;        // Usado para interpolar el offset en z de la cámara
  228. var vector CamOffset;           // Offset de la cámara en tercera persona
  229.  
  230. /******************************************************************************
  231. Animation Properties
  232. ******************************************************************************/
  233. var AnimNodeSlot MeleeAnimNode;
  234.  
  235. simulated event PostInitAnimTree(SkeletalMeshComponent SkelComp)
  236. {
  237.     // Se busca la referencia del nodo de animaciones melee
  238.     MeleeAnimNode = AnimNodeSlot(SkelComp.FindAnimNode('MeleeAnim'));
  239. }
  240.  
  241.  
  242. // Sobreescribe una función para que se vea al pawn por defecto
  243. // Llama a la Camara cuando este actor se convierte en su ViewTarget
  244. simulated event BecomeViewTarget( PlayerController PC )
  245. {
  246.     local UTPlayerController UTPC;
  247.  
  248.     // Por defecto esta llamada pone los brazos al Pawn y el arma inicial (y otras cosas)
  249.     Super.BecomeViewTarget(PC);
  250.  
  251.     if (LocalPlayer(PC.Player) != None)
  252.     {
  253.         UTPC = UTPlayerController(PC);
  254.         if (UTPC != None)
  255.         {
  256.             // Activa la vista trasera (Poner la camara en tercera persona y hace desaparecer brazos y armas de primera persona
  257.             UTPC.SetBehindView(true);
  258.             // Esto no es necesario
  259.              //SetMeshVisibility(UTPC.bBehindView);
  260.         }
  261.     }
  262. }
  263.  
  264. // Función que calcula la posición de la cámara
  265. // Es un ripoff de la función CalcThirdPersonCam de UTPawn, quitando los casos de DebugCam o cuado se gana la partida
  266. simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc,
  267.                         out rotator out_CamRot, out float out_FOV )
  268. {
  269.     local vector CamStart, HitLocation, HitNormal, CamDirX, CamDirY, CamDirZ, CurrentCamOffset;
  270.     local float DesiredCameraZOffset;
  271.  
  272.     // El punto inicial de la cámara es la posición del Pawn
  273.     CamStart = Location;
  274.     CurrentCamOffset = CamOffset;
  275.  
  276.     // Si está vivo pone un offset en Z (hacia arriba) del alto del mesh * 1.2
  277.     DesiredCameraZOffset = (Health > 0) ? 1.0 * GetCollisionHeight() + Mesh.Translation.Z : 0.f;
  278.  
  279.     // Hace una interpolación si el tiempo entre frames es suficientemente pequeño (Se veria si cambiara el offset en Z)
  280.     CameraZOffset = (fDeltaTime < 0.2) ? DesiredCameraZOffset * 5 * fDeltaTime + (1 - 5*fDeltaTime) * CameraZOffset : DesiredCameraZOffset;
  281.  
  282.     if ( Health <= 0 )
  283.     {
  284.         CurrentCamOffset = vect(0,0,0);
  285.         CurrentCamOffset.X = GetCollisionRadius();
  286.        
  287.         // adjust camera position to make sure it's not clipping into world
  288.         // @todo fixmesteve.  Note that you can still get clipping if FindSpot fails (happens rarely)
  289.         FindSpot(GetCollisionExtent(),CamStart);
  290.     }
  291.  
  292.     // Se suma a la posición inicial el offset de Z
  293.     CamStart.Z += CameraZOffset;
  294.     // Se extraen los ejes de la rotación de la cámara
  295.     GetAxes(out_CamRot, CamDirX, CamDirY, CamDirZ);
  296.     // Escala de la camara (zoom)
  297.     CamDirX *= CurrentCameraScale;
  298.  
  299.     // Se interpola la escala de la cámara suavemente (lo que sería el zoom)
  300.     if (CurrentCameraScale < CameraScale)
  301.     {
  302.         CurrentCameraScale = FMin(CameraScale, CurrentCameraScale + 1 * FMax(CameraScale - CurrentCameraScale, 0.3)*fDeltaTime);
  303.     }
  304.     else if (CurrentCameraScale > CameraScale)
  305.     {
  306.         CurrentCameraScale = FMax(CameraScale, CurrentCameraScale - 1 * FMax(CameraScale - CurrentCameraScale, 0.3)*fDeltaTime);
  307.     }
  308.  
  309.     // No parece que entre aquí nunca
  310.     if (CamDirX.Z > GetCollisionHeight())
  311.     {
  312.         CamDirX *= square(cos(out_CamRot.Pitch * 0.0000958738)); // 0.0000958738 = 2*PI/65536
  313.     }
  314.  
  315.     // Posición final de la cámara
  316.     out_CamLoc = CamStart - CamDirX*CurrentCamOffset.X + CurrentCamOffset.Y*CamDirY + CurrentCamOffset.Z*CamDirZ;
  317.  
  318.     // Se traza un rayo para calcular posibles colisiones con la geometría
  319.     if (Trace(HitLocation, HitNormal, out_CamLoc, CamStart, false, vect(12,12,12)) != None)
  320.     {
  321.         out_CamLoc = HitLocation;
  322.     }
  323.  
  324.     return true;
  325. }
  326.  
  327. // Sobreescribe la funcion de Pawn
  328. function AddDefaultInventory()
  329. {
  330.     // Se le da al Pawn el arma al comenzar
  331.     InvManager.CreateInventory(class'KHR.KHRKingdomKey');
  332.     InvManager.CreateInventory(class'KHR.KHRRulerOfDarkness');
  333. }
  334.  
  335. // Cambio de arma, llamado desde PFMPlayerController
  336. simulated function SwitchWeapon(byte NewGroup)
  337. {
  338.     if (KHRInventory(InvManager) != None)
  339.     {
  340.         // Se le indica al Manager del Inventario que cambie de arma
  341.         KHRInventory(InvManager).SwitchWeapon(NewGroup);
  342.     }
  343. }
  344.  
  345. defaultproperties
  346. {
  347.     HP = 100;
  348.     totalHP = 100;
  349.     MP = 60;
  350.     totalMP = 60;
  351.     GroundSpeed = 300;
  352.     AirSpeed = 200;
  353.  
  354.     InventoryManagerClass=class'KHR.KHRInventory'
  355.  
  356.     // Propiedades de cámara
  357.     CameraScale=40.0
  358.     CurrentCameraScale=0.0
  359.     CamOffset=(X=5.0,Y=0.0,Z=25.0)
  360.    
  361.     // Light Enviroment
  362.     Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
  363.     bCastShadows=true
  364.     bShadowFromEnvironment=true
  365.     bSynthesizeSHLight=TRUE
  366.     bIsCharacterLightEnvironment=TRUE
  367.     MinTimeBetweenFullUpdates=0.1
  368.     End Object
  369.    
  370.     Components.Add(MyLightEnvironment)
  371.     LightEnvironment=MyLightEnvironment
  372.    
  373.     // Pawn Character //
  374.     Begin Object Class=SkeletalMeshComponent Name=TestSkeletalMesh
  375.         CastShadow=true
  376.         bOwnerNoSee=false
  377.         bCastDynamicShadow=true
  378.         LightEnvironment=MyLightEnvironment
  379.         LightingChannels=(Dynamic=true,Static=true)
  380.         BlockRigidBody=true;
  381.         CollideActors=true;
  382.         BlockZeroExtent=true;
  383.         SkeletalMesh=SkeletalMesh'PC.Mesh.p01zz00'
  384.         AnimSets(0)=AnimSet'PC.Animations.p01zz00_mset'
  385.         AnimTreeTemplate=AnimTree'PC.Animations.p01zz00_animtree'
  386.     End Object
  387.    
  388.     //Set up collision cylinder. //
  389.     Mesh=TestSkeletalMesh;
  390.     Components.Add(TestSkeletalMesh);
  391.     CollisionType=COLLIDE_BlockAll
  392.        
  393.     Begin Object Name=CollisionCylinder
  394.         CollisionRadius=+0021.000000
  395.         CollisionHeight=+0044.000000
  396.         Translation=(Z=47)
  397.     End Object
  398.         CylinderComponent=CollisionCylinder
  399. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement