long-log / samples_longbench_lcc_2026-01-29T09-51-37.538484.jsonl
Yi30's picture
Add files using upload-large-folder tool
b8175d4 verified
{"doc_id": 0, "doc": {"question": "", "context": "Please complete the code given below. \nusing System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing Server.Commands;\nusing Server.Engines.PartySystem;\nusing Server.Factions;\nusing Server.Gumps;\nusing Server.Items;\nusing Server.Mobiles;\nusing Server.Network;\nusing Server.Spells;\nusing Server.Spells.Bushido;\nusing Server.Spells.Chivalry;\nusing Server.Spells.Necromancy;\nusing Server.Spells.Ninjitsu;\nusing Server.Spells.Seventh;\nusing Server.Spells.Spellweaving;\nnamespace Server.Engines.ConPVP\n{\n public delegate void CountdownCallback( int count );\n\tpublic class DuelContext\n\t{\n\t\tprivate Mobile m_Initiator;\n\t\tprivate ArrayList m_Participants;\n\t\tprivate Ruleset m_Ruleset;\n\t\tprivate Arena m_Arena;\n\t\tprivate bool m_Registered = true;\n\t\tprivate bool m_Finished, m_Started;\n\t\tprivate bool m_ReadyWait;\n\t\tprivate int m_ReadyCount;\n\t\tprivate bool m_Rematch;\n\t\tpublic bool Rematch{ get{ return m_Rematch; } }\n\t\tpublic bool ReadyWait{ get{ return m_ReadyWait; } }\n\t\tpublic int ReadyCount{ get{ return m_ReadyCount; } }\n\t\tpublic bool Registered{ get{ return m_Registered; } }\n\t\tpublic bool Finished{ get{ return m_Finished; } }\n\t\tpublic bool Started{ get{ return m_Started; } }\n\t\tpublic Mobile Initiator{ get{ return m_Initiator; } }\n\t\tpublic ArrayList Participants{ get{ return m_Participants; } }\n\t\tpublic Ruleset Ruleset{ get{ return m_Ruleset; } }\n\t\tpublic Arena Arena{ get{ return m_Arena; } }\n\t\tprivate bool CantDoAnything( Mobile mob )\n\t\t{\n\t\t\tif ( m_EventGame != null )\n\t\t\t\treturn m_EventGame.CantDoAnything( mob );\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\t\tpublic static bool IsFreeConsume( Mobile mob )\n\t\t{\n\t\t\tPlayerMobile pm = mob as PlayerMobile;\n\t\t\tif ( pm == null || pm.DuelContext == null || pm.DuelContext.m_EventGame == null )\n\t\t\t\treturn false;\n\t\t\treturn pm.DuelContext.m_EventGame.FreeConsume;\n\t\t}\n\t\tpublic void DelayBounce( TimeSpan ts, Mobile mob, Container corpse )\n\t\t{\n\t\t\tTimer.DelayCall( ts, new TimerStateCallback( DelayBounce_Callback ), new object[]{ mob, corpse } );\n\t\t}\n\t\tpublic static bool AllowSpecialMove( Mobile from, string name, SpecialMove move )\n\t\t{\n\t\t\tPlayerMobile pm = from as PlayerMobile;\n\t\t\tif( pm == null )\n\t\t\t\treturn true;\n\t\t\tDuelContext dc = pm.DuelContext;\n\t\t\treturn (dc == null || dc.InstAllowSpecialMove( from, name, move ));\n\t\t}\n\t\tpublic bool InstAllowSpecialMove( Mobile from, string name, SpecialMove move )\n\t\t{\n\t\t\tif ( !m_StartedBeginCountdown )\n\t\t\t\treturn true;\n\t\t\tDuelPlayer pl = Find( from );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn true;\n\t\t\tif ( CantDoAnything( from ) )\n\t\t\t\treturn false;\n\t\t\tstring title = null;\n\t\t\tif( move is NinjaMove )\n\t\t\t\ttitle = \"Bushido\";\n\t\t\telse if( move is SamuraiMove )\n\t\t\t\ttitle = \"Ninjitsu\";\n\t\t\tif ( title == null || name == null || m_Ruleset.GetOption( title, name ) )\n\t\t\t\treturn true;\n\t\t\tfrom.SendMessage( \"The dueling ruleset prevents you from using this move.\" );\n\t\t\treturn false;\n\t\t}\n\t\tpublic bool AllowSpellCast( Mobile from, Spell spell )\n\t\t{\n\t\t\tif ( !m_StartedBeginCountdown )\n\t\t\t\treturn true;\n\t\t\tDuelPlayer pl = Find( from );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn true;\n\t\t\tif ( CantDoAnything( from ) )\n\t\t\t\treturn false;\n\t\t\tif ( spell is Server.Spells.Fourth.RecallSpell )\n\t\t\t\tfrom.SendMessage( \"You may not cast this spell.\" );\n\t\t\tstring title = null, option = null;\n\t\t\tif( spell is ArcanistSpell )\n\t\t\t{\n\t\t\t\ttitle = \"Spellweaving\";\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\telse if ( spell is PaladinSpell )\n\t\t\t{\n\t\t\t\ttitle = \"Chivalry\";\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\telse if ( spell is NecromancerSpell )\n\t\t\t{\n\t\t\t\ttitle = \"Necromancy\";\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\telse if ( spell is NinjaSpell )\n\t\t\t{\n\t\t\t\ttitle = \"Ninjitsu\";\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\telse if ( spell is SamuraiSpell )\n\t\t\t{\n\t\t\t\ttitle = \"Bushido\";\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\telse if( spell is MagerySpell )\n\t\t\t{\n\t\t\t\tswitch( ((MagerySpell)spell).Circle )\n\t\t\t\t{\n\t\t\t\t\tcase SpellCircle.First: title = \"1st Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Second: title = \"2nd Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Third: title = \"3rd Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Fourth: title = \"4th Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Fifth: title = \"5th Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Sixth: title = \"6th Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Seventh: title = \"7th Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Eighth: title = \"8th Circle\"; break;\n\t\t\t\t}\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ttitle = \"Other Spell\";\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\tif ( title == null || option == null || m_Ruleset.GetOption( title, option ) )\n\t\t\t\treturn true;\n\t\t\tfrom.SendMessage( \"The dueling ruleset prevents you from casting this spell.\" );\n\t\t\treturn false;\n\t\t}\n\t\tpublic bool AllowItemEquip( Mobile from, Item item )\n\t\t{\n\t\t\tif ( !m_StartedBeginCountdown )\n\t\t\t\treturn true;\n\t\t\tDuelPlayer pl = Find( from );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn true;\n\t\t\tif ( item is Dagger || CheckItemEquip( from, item ) )\n\t\t\t\treturn true;\n\t\t\tfrom.SendMessage( \"The dueling ruleset prevents you from equiping this item.\" );\n\t\t\treturn false;\n\t\t}\n\t\tpublic static bool AllowSpecialAbility( Mobile from, string name, bool message )\n\t\t{\n\t\t\tPlayerMobile pm = from as PlayerMobile;\n\t\t\tif ( pm == null )\n\t\t\t\treturn true;\n\t\t\tDuelContext dc = pm.DuelContext;\n\t\t\treturn ( dc == null || dc.InstAllowSpecialAbility( from, name, message ) );\n\t\t}\n\t\tpublic bool InstAllowSpecialAbility( Mobile from, string name, bool message )\n\t\t{\n\t\t\tif ( !m_StartedBeginCountdown )\n\t\t\t\treturn true;\n\t\t\tDuelPlayer pl = Find( from );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn true;\n\t\t\tif ( CantDoAnything( from ) )\n\t\t\t\treturn false;\n\t\t\tif ( m_Ruleset.GetOption( \"Combat Abilities\", name ) )\n\t\t\t\treturn true;\n\t\t\tif ( message )\n\t\t\t\tfrom.SendMessage( \"The dueling ruleset prevents you from using this combat ability.\" );\n\t\t\treturn false;\n\t\t}\n\t\tpublic bool CheckItemEquip( Mobile from, Item item )\n\t\t{\n\t\t\tif ( item is Fists )\n\t\t\t{\n\t\t\t\tif ( !m_Ruleset.GetOption( \"Weapons\", \"Wrestling\" ) )\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse if ( item is BaseArmor )\n\t\t\t{\n\t\t\t\tBaseArmor armor = (BaseArmor)item;\n\t\t\t\tif ( armor.ProtectionLevel > ArmorProtectionLevel.Regular && !m_Ruleset.GetOption( \"Armor\", \"Magical\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( !Core.AOS && armor.Resource != armor.DefaultResource && !m_Ruleset.GetOption( \"Armor\", \"Colored\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( armor is BaseShield && !m_Ruleset.GetOption( \"Armor\", \"Shields\" ) )\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse if ( item is BaseWeapon )\n\t\t\t{\n\t\t\t\tBaseWeapon weapon = (BaseWeapon)item;\n\t\t\t\tif ( (weapon.DamageLevel > WeaponDamageLevel.Regular || weapon.AccuracyLevel > WeaponAccuracyLevel.Regular) && !m_Ruleset.GetOption( \"Weapons\", \"Magical\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( !Core.AOS && weapon.Resource != CraftResource.Iron && weapon.Resource != CraftResource.None && !m_Ruleset.GetOption( \"Weapons\", \"Runics\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( weapon is BaseRanged && !m_Ruleset.GetOption( \"Weapons\", \"Ranged\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( !(weapon is BaseRanged) && !m_Ruleset.GetOption( \"Weapons\", \"Melee\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( weapon.PoisonCharges > 0 && weapon.Poison != null && !m_Ruleset.GetOption( \"Weapons\", \"Poisoned\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( weapon is BaseWand && !m_Ruleset.GetOption( \"Items\", \"Wands\" ) )\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tpublic bool AllowSkillUse( Mobile from, SkillName skill )\n\t\t{\n\t\t\tif ( !m_StartedBeginCountdown )\n\t\t\t\treturn true;\n\t\t\tDuelPlayer pl = Find( from );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn true;\n\t\t\tif ( CantDoAnything( from ) )\n\t\t\t\treturn false;\n\t\t\tint id = (int)skill;\n\t\t\tif ( id >= 0 && id < SkillInfo.Table.Length )\n\t\t\t{\n\t\t\t\tif ( m_Ruleset.GetOption( \"Skills\", SkillInfo.Table[id].Name ) )\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\tfrom.SendMessage( \"The dueling ruleset prevents you from using this skill.\" );\n\t\t\treturn false;\n\t\t}\n\t\tpublic bool AllowItemUse( Mobile from, Item item )\n\t\t{\n\t\t\tif ( !m_StartedBeginCountdown )\n\t\t\t\treturn true;\n\t\t\tDuelPlayer pl = Find( from );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn true;\n\t\t\tif ( !(item is BaseRefreshPotion) )\n\t\t\t{\n\t\t\t\tif ( CantDoAnything( from ) )\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\tstring title = null, option = null;\n\t\t\tif ( item is BasePotion )\n\t\t\t{\n\t\t\t\ttitle = \"Potions\";\n\t\t\t\tif ( item is BaseAgilityPotion )\n\t\t\t\t\toption = \"Agility\";\n\t\t\t\telse if ( item is BaseCurePotion )\n\t\t\t\t\toption = \"Cure\";\n\t\t\t\telse if ( item is BaseHealPotion )\n\t\t\t\t\toption = \"Heal\";\n\t\t\t\telse if ( item is NightSightPotion )\n\t\t\t\t\toption = \"Nightsight\";\n\t\t\t\telse if ( item is BasePoisonPotion )\n\t\t\t\t\toption = \"Poison\";\n\t\t\t\telse if ( item is BaseStrengthPotion )\n\t\t\t\t\toption = \"Strength\";\n\t\t\t\telse if ( item is BaseExplosionPotion )\n\t\t\t\t\toption = \"Explosion\";\n\t\t\t\telse if ( item is BaseRefreshPotion )\n\t\t\t\t\toption = \"Refresh\";\n\t\t\t}\n\t\t\telse if ( item is Bandage )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Bandages\";\n\t\t\t}\n\t\t\telse if ( item is TrapableContainer )\n\t\t\t{\n\t\t\t\tif ( ((TrapableContainer)item).TrapType != TrapType.None )\n\t\t\t\t{\n\t\t\t\t\ttitle = \"Items\";\n\t\t\t\t\toption = \"Trapped Containers\";\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( item is Bola )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Bolas\";\n\t\t\t}\n\t\t\telse if ( item is OrangePetals )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Orange Petals\";\n\t\t\t}\n\t\t\telse if ( item is EtherealMount || item.Layer == Layer.Mount )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Mounts\";\n\t\t\t}\n\t\t\telse if ( item is LeatherNinjaBelt )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Shurikens\";\n\t\t\t}\n\t\t\telse if ( item is Fukiya )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Fukiya Darts\";\n\t\t\t}\n\t\t\telse if ( item is FireHorn )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Fire Horns\";\n\t\t\t}\n\t\t\telse if ( item is BaseWand )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Wands\";\n\t\t\t}\n\t\t\tif ( title != null && option != null && m_StartedBeginCountdown && !m_Started )\n\t\t\t{\n\t\t\t\tfrom.SendMessage( \"You may not use this item before the duel begins.\" );\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse if ( item is BasePotion && !(item is BaseExplosionPotion) && !(item is BaseRefreshPotion) && IsSuddenDeath )\n\t\t\t{\n\t\t\t\tfrom.SendMessage( 0x22, \"You may not drink potions in sudden death.\" );\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse if ( item is Bandage && IsSuddenDeath )\n\t\t\t{\n\t\t\t\tfrom.SendMessage( 0x22, \"You may not use bandages in sudden death.\" );\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif ( title == null || option == null || m_Ruleset.GetOption( title, option ) )\n\t\t\t\treturn true;\n\t\t\tfrom.SendMessage( \"The dueling ruleset prevents you from using this item.\" );\n\t\t\treturn false;\n\t\t}\n\t\tprivate void DelayBounce_Callback( object state )\n\t\t{\n\t\t\tobject[] states = (object[])state;\n\t\t\tMobile mob = (Mobile) states[0];\n\t\t\tContainer corpse = (Container) states[1];\n\t\t\tRemoveAggressions( mob );\n\t\t\tSendOutside( mob );\n\t\t\tRefresh( mob, corpse );\n\t\t\tDebuff( mob );\n\t\t\tCancelSpell( mob );\n\t\t\tmob.Frozen = false;\n\t\t}\n\t\tpublic void OnMapChanged( Mobile mob )\n\t\t{\n\t\t\tOnLocationChanged( mob );\n\t\t}\n\t\tpublic void OnLocationChanged( Mobile mob )\n\t\t{\n\t\t\tif ( !m_Registered || !m_StartedBeginCountdown || m_Finished )\n\t\t\t\treturn;\n\t\t\tArena arena = m_Arena;\n\t\t\tif ( arena == null )\n\t\t\t\treturn;\n\t\t\tif ( mob.Map == arena.Facet && arena.Bounds.Contains( mob.Location ) )\n\t\t\t\treturn;\n\t\t\tDuelPlayer pl = Find( mob );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn;\n\t\t\tif ( mob.Map == Map.Internal ) {\n\t\t\t\t// they've logged out\n\t\t\t\tif ( mob.LogoutMap == arena.Facet && arena.Bounds.Contains( mob.LogoutLocation ) ) {\n\t\t\t\t\t// they logged out inside the arena.. set them to eject on login\n\t\t\t\t\tmob.LogoutLocation = arena.Outside;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpl.Eliminated = true;\n\t\t\tmob.LocalOverheadMessage( MessageType.Regular, 0x22, false, \"You have forfeited your position in the duel.\" );\n\t\t\tmob.NonlocalOverheadMessage( MessageType.Regular, 0x22, false, String.Format( \"{0} has forfeited by leaving the dueling arena.\", mob.Name ) );\n\t\t\tParticipant winner = CheckCompletion();\n\t\t\tif ( winner != null )\n\t\t\t\tFinish( winner );\n\t\t}\n\t\tprivate bool m_Yielding;\n\t\tpublic void OnDeath( Mobile mob, Container corpse )\n\t\t{\n\t\t\tif ( !m_Registered || !m_Started )\n\t\t\t\treturn;\n\t\t\tDuelPlayer pl = Find( mob );\n\t\t\tif ( pl != null && !pl.Eliminated )\n\t\t\t{\n\t\t\t\tif ( m_EventGame != null && !m_EventGame.OnDeath( mob, corpse ) )\n\t\t\t\t\treturn;\n\t\t\t\tpl.Eliminated = true;\n\t\t\t\tif ( mob.Poison != null )\n\t\t\t\t\tmob.Poison = null;\n\t\t\t\tRequip( mob, corpse );\n\t\t\t\tDelayBounce( TimeSpan.FromSeconds( 4.0 ), mob, corpse );\n\t\t\t\tParticipant winner = CheckCompletion();\n\t\t\t\tif ( winner != null )\n\t\t\t\t{\n\t\t\t\t\tFinish( winner );\n\t\t\t\t}\n\t\t\t\telse if ( !m_Yielding )\n\t\t\t\t{\n\t\t\t\t\tmob.LocalOverheadMessage( MessageType.Regular, 0x22, false, \"You have been defeated.\" );\n\t\t\t\t\tmob.NonlocalOverheadMessage( MessageType.Regular, 0x22, false, String.Format( \"{0} has been defeated.\", mob.Name ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpublic bool CheckFull()\n\t\t{\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tif ( p.HasOpenSlot )\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tpublic void Requip( Mobile from, Container cont )\n\t\t{\n\t\t\tCorpse corpse = cont as Corpse;\n\t\t\tif ( corpse == null )\n\t\t\t\treturn;\n\t\t\tList<Item> items = new List<Item>( corpse.Items );\n\t\t\tbool gathered = false;\n\t\t\tbool didntFit = false;\n\t\t\tContainer pack = from.Backpack;\n\t\t\tfor ( int i = 0; !didntFit && i < items.Count; ++i )\n\t\t\t{\n\t\t\t\tItem item = items[i];\n\t\t\t\tPoint3D loc = item.Location;\n\t\t\t\tif ( (item.Layer == Layer.Hair || item.Layer == Layer.FacialHair) || !item.Movable )\n\t\t\t\t\tcontinue;\n\t\t\t\tif ( pack != null )\n\t\t\t\t{\n\t\t\t\t\tpack.DropItem( item );\n\t\t\t\t\tgathered = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tdidntFit = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcorpse.Carved = true;\n\t\t\tif ( corpse.ItemID == 0x2006 )\n\t\t\t{\n\t\t\t\tcorpse.ProcessDelta();\n\t\t\t\tcorpse.SendRemovePacket();\n\t\t\t\tcorpse.ItemID = Utility.Random( 0xECA, 9 ); // bone graphic\n\t\t\t\tcorpse.Hue = 0;\n\t\t\t\tcorpse.ProcessDelta();\n\t\t\t\tMobile killer = from.FindMostRecentDamager( false );\n\t\t\t\tif ( killer != null && killer.Player )\n\t\t\t\t\tkiller.AddToBackpack( new Head( m_Tournament == null ? HeadType.Duel : HeadType.Tournament, from.Name ) );\n\t\t\t}\n\t\t\tfrom.PlaySound( 0x3E3 );\n\t\t\tif ( gathered && !didntFit )\n\t\t\t\tfrom.SendLocalizedMessage( 1062471 ); // You quickly gather all of your belongings.\n\t\t\telse if ( gathered && didntFit )\n\t\t\t\tfrom.SendLocalizedMessage( 1062472 ); // You gather some of your belongings. The rest remain on the corpse.\n\t\t}\n\t\tpublic void Refresh( Mobile mob, Container cont )\n\t\t{\n\t\t\tif ( !mob.Alive )\n\t\t\t{\n\t\t\t\tmob.Resurrect();\n\t\t\t\tDeathRobe robe = mob.FindItemOnLayer( Layer.OuterTorso ) as DeathRobe;\n\t\t\t\tif ( robe != null )\n\t\t\t\t\trobe.Delete();\n\t\t\t\tif ( cont is Corpse )\n\t\t\t\t{\n\t\t\t\t\tCorpse corpse = (Corpse) cont;\n\t\t\t\t\tfor ( int i = 0; i < corpse.EquipItems.Count; ++i )\n\t\t\t\t\t{\n\t\t\t\t\t\tItem item = corpse.EquipItems[i];\n\t\t\t\t\t\tif ( item.Movable && item.Layer != Layer.Hair && item.Layer != Layer.FacialHair && item.IsChildOf( mob.Backpack ) )\n\t\t\t\t\t\t\tmob.EquipItem( item );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tmob.Hits = mob.HitsMax;\n\t\t\tmob.Stam = mob.StamMax;\n\t\t\tmob.Mana = mob.ManaMax;\n\t\t\tmob.Poison = null;\n\t\t}\n\t\tpublic void SendOutside( Mobile mob )\n\t\t{\n\t\t\tif ( m_Arena == null )\n\t\t\t\treturn;\n\t\t\tmob.Combatant = null;\n\t\t\tmob.MoveToWorld( m_Arena.Outside, m_Arena.Facet );\n\t\t}\n\t\tprivate Point3D m_GatePoint;\n\t\tprivate Map m_GateFacet;\n\t\tpublic void Finish( Participant winner )\n\t\t{\n\t\t\tif ( m_Finished )\n\t\t\t\treturn;\n\t\t\tEndAutoTie();\n\t\t\tStopSDTimers();\n\t\t\tm_Finished = true;\n\t\t\tfor ( int i = 0; i < winner.Players.Length; ++i )\n\t\t\t{\n\t\t\t\tDuelPlayer pl = winner.Players[i];\n\t\t\t\tif ( pl != null && !pl.Eliminated )\n\t\t\t\t\tDelayBounce( TimeSpan.FromSeconds( 8.0 ), pl.Mobile, null );\n\t\t\t}\n\t\t\twinner.Broadcast( 0x59, null, winner.Players.Length == 1 ? \"{0} has won the duel.\" : \"{0} and {1} team have won the duel.\", winner.Players.Length == 1 ? \"You have won the duel.\" : \"Your team has won the duel.\" );\n\t\t\tif ( m_Tournament != null && winner.TournyPart != null )\n\t\t\t{\n\t\t\t\tm_Match.Winner = winner.TournyPart;\n\t\t\t\twinner.TournyPart.WonMatch( m_Match );\n\t\t\t\tm_Tournament.HandleWon( m_Arena, m_Match, winner.TournyPart );\n\t\t\t}\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant loser = (Participant)m_Participants[i];\n\t\t\t\tif ( loser != winner )\n\t\t\t\t{\n\t\t\t\t\tloser.Broadcast( 0x22, null, loser.Players.Length == 1 ? \"{0} has lost the duel.\" : \"{0} and {1} team have lost the duel.\", loser.Players.Length == 1 ? \"You have lost the duel.\" : \"Your team has lost the duel.\" );\n\t\t\t\t\tif ( m_Tournament != null && loser.TournyPart != null )\n\t\t\t\t\t\tloser.TournyPart.LostMatch( m_Match );\n\t\t\t\t}\n\t\t\t\tfor ( int j = 0; j < loser.Players.Length; ++j )\n\t\t\t\t{\n\t\t\t\t\tif ( loser.Players[j] != null )\n\t\t\t\t\t{\n\t\t\t\t\t\tRemoveAggressions( loser.Players[j].Mobile );\n\t\t\t\t\t\tloser.Players[j].Mobile.Delta( MobileDelta.Noto );\n\t\t\t\t\t\tloser.Players[j].Mobile.CloseGump( typeof( BeginGump ) );\n\t\t\t\t\t\tif ( m_Tournament != null )\n\t\t\t\t\t\t\tloser.Players[j].Mobile.SendEverything();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( IsOneVsOne )\n\t\t\t{\n\t\t\t\tDuelPlayer dp1 = ((Participant)m_Participants[0]).Players[0];\n\t\t\t\tDuelPlayer dp2 = ((Participant)m_Participants[1]).Players[0];\n\t\t\t\tif ( dp1 != null && dp2 != null )\n\t\t\t\t{\n\t\t\t\t\tAward( dp1.Mobile, dp2.Mobile, dp1.Participant == winner );\n\t\t\t\t\tAward( dp2.Mobile, dp1.Mobile, dp2.Participant == winner );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( m_EventGame != null )\n\t\t\t\tm_EventGame.OnStop();\n\t\t\tTimer.DelayCall( TimeSpan.FromSeconds( 9.0 ), new TimerCallback( UnregisterRematch ) );\n\t\t}\n\t\tpublic void Award( Mobile us, Mobile them, bool won )\n\t\t{\n\t\t\tLadder ladder = ( m_Arena == null ? Ladder.Instance : m_Arena.AcquireLadder() );\n\t\t\tif ( ladder == null )\n\t\t\t\treturn;\n\t\t\tLadderEntry ourEntry = ladder.Find( us );\n\t\t\tLadderEntry theirEntry = ladder.Find( them );\n\t\t\tif ( ourEntry == null || theirEntry == null )\n\t\t\t\treturn;\n\t\t\tint xpGain = Ladder.GetExperienceGain( ourEntry, theirEntry, won );\n\t\t\tif ( xpGain == 0 )\n\t\t\t\treturn;\n\t\t\tif ( m_Tournament != null )\n\t\t\t\txpGain *= ( xpGain > 0 ? 5 : 2 );\n\t\t\tif ( won )\n\t\t\t\t++ourEntry.Wins;\n\t\t\telse\n\t\t\t\t++ourEntry.Losses;\n\t\t\tint oldLevel = Ladder.GetLevel( ourEntry.Experience );\n\t\t\tourEntry.Experience += xpGain;\n\t\t\tif ( ourEntry.Experience < 0 )\n\t\t\t\tourEntry.Experience = 0;\n\t\t\tladder.UpdateEntry( ourEntry );\n\t\t\tint newLevel = Ladder.GetLevel( ourEntry.Experience );\n\t\t\tif ( newLevel > oldLevel )\n\t\t\t\tus.SendMessage( 0x59, \"You have achieved level {0}!\", newLevel );\n\t\t\telse if ( newLevel < oldLevel )\n\t\t\t\tus.SendMessage( 0x22, \"You have lost a level. You are now at {0}.\", newLevel );\n\t\t}\n\t\tpublic void UnregisterRematch()\n\t\t{\n\t\t\tUnregister(true);\n\t\t}\n\t\tpublic void Unregister()\n\t\t{\n\t\t\tUnregister(false);\n\t\t}\n\t\tpublic void Unregister( bool queryRematch )\n\t\t{\n\t\t\tDestroyWall();\n\t\t\tif ( !m_Registered )\n\t\t\t\treturn;\n\t\t\tm_Registered = false;\n\t\t\tif ( m_Arena != null )\n\t\t\t\tm_Arena.Evict();\n\t\t\tStopSDTimers();\n\t\t\tType[] types = new Type[]{ typeof( BeginGump ), typeof( DuelContextGump ), typeof( ParticipantGump ), typeof( PickRulesetGump ), typeof( ReadyGump ), typeof( ReadyUpGump ), typeof( RulesetGump ) };\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tfor ( int j = 0; j < p.Players.Length; ++j )\n\t\t\t\t{\n\t\t\t\t\tDuelPlayer pl = (DuelPlayer)p.Players[j];\n\t\t\t\t\tif ( pl == null )\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tif ( pl.Mobile is PlayerMobile )\n\t\t\t\t\t\t((PlayerMobile)pl.Mobile).DuelPlayer = null;\n\t\t\t\t\tfor ( int k = 0; k < types.Length; ++k )\n\t\t\t\t\t\tpl.Mobile.CloseGump( types[k] );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( queryRematch && m_Tournament == null )\n\t\t\t\tQueryRematch();\n\t\t}\n\t\tpublic void QueryRematch()\n\t\t{\n\t\t\tDuelContext dc = new DuelContext( m_Initiator, m_Ruleset.Layout, false );\n\t\t\tdc.m_Ruleset = m_Ruleset;\n\t\t\tdc.m_Rematch = true;\n\t\t\tdc.m_Participants.Clear();\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant oldPart = (Participant)m_Participants[i];\n\t\t\t\tParticipant newPart = new Participant( dc, oldPart.Players.Length );\n\t\t\t\tfor ( int j = 0; j < oldPart.Players.Length; ++j )\n\t\t\t\t{\n\t\t\t\t\tDuelPlayer oldPlayer = oldPart.Players[j];\n\t\t\t\t\tif ( oldPlayer != null )\n\t\t\t\t\t\tnewPart.Players[j] = new DuelPlayer( oldPlayer.Mobile, newPart );\n\t\t\t\t}\n\t\t\t\tdc.m_Participants.Add( newPart );\n\t\t\t}\n\t\t\tdc.CloseAllGumps();\n\t\t\tdc.SendReadyUpGump();\n\t\t}\n\t\tpublic DuelPlayer Find( Mobile mob )\n\t\t{\n\t\t\tif ( mob is PlayerMobile )\n\t\t\t{\n\t\t\t\tPlayerMobile pm = (PlayerMobile)mob;\n\t\t\t\tif ( pm.DuelContext == this )\n\t\t\t\t\treturn pm.DuelPlayer;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tDuelPlayer pl = p.Find( mob );\n\t\t\t\tif ( pl != null )\n\t\t\t\t\treturn pl;\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\t\tpublic bool IsAlly( Mobile m1, Mobile m2 )\n\t\t{\n\t\t\tDuelPlayer pl1 = Find( m1 );\n\t\t\tDuelPlayer pl2 = Find( m2 );\n\t\t\treturn ( pl1 != null && pl2 != null && pl1.Participant == pl2.Participant );\n\t\t}\n\t\tpublic Participant CheckCompletion()\n\t\t{\n\t\t\tParticipant winner = null;\n\t\t\tbool hasWinner = false;\n\t\t\tint eliminated = 0;\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tif ( p.Eliminated )\n\t\t\t\t{\n\t\t\t\t\t++eliminated;\n\t\t\t\t\tif ( eliminated == (m_Participants.Count - 1) )\n\t\t\t\t\t\thasWinner = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\twinner = p;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( hasWinner )\n\t\t\t\treturn winner == null ? (Participant) m_Participants[0] : winner;\n\t\t\treturn null;\n\t\t}\n\t\tprivate Timer m_Countdown;\n\t\tpublic void StartCountdown( int count, CountdownCallback cb )\n\t\t{\n\t\t\tcb(count);\n\t\t\tm_Countdown=Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), TimeSpan.FromSeconds( 1.0 ), count, new TimerStateCallback( Countdown_Callback ), new object[]{ count-1, cb } );\n\t\t}\n\t\tpublic void StopCountdown()\n\t\t{\n\t\t\tif ( m_Countdown != null )\n\t\t\t\tm_Countdown.Stop();\n\t\t\tm_Countdown = null;\n\t\t}\n\t\tprivate void Countdown_Callback( object state )\n\t\t{\n\t\t\tobject[] states = (object[])state;\n\t\t\tint count = (int)states[0];\n\t\t\tCountdownCallback cb = (CountdownCallback)states[1];\n\t\t\tif ( count==0 )\n\t\t\t{\n\t\t\t\tif ( m_Countdown != null )\n\t\t\t\t\tm_Countdown.Stop();\n\t\t\t\tm_Countdown=null;\n\t\t\t}\n\t\t\tcb( count );\n\t\t\tstates[0] = count - 1;\n\t\t}\n\t\tprivate Timer m_AutoTieTimer;\n\t\tprivate bool m_Tied;\n\t\tpublic bool Tied{ get{ return m_Tied; } }\n\t\tprivate bool m_IsSuddenDeath;\n\t\tpublic bool IsSuddenDeath{ get{ return m_IsSuddenDeath; } set{ m_IsSuddenDeath = value; } }\n\t\tprivate Timer m_SDWarnTimer, m_SDActivateTimer;\n\t\tpublic void StopSDTimers()\n\t\t{\n\t\t\tif ( m_SDWarnTimer != null )\n\t\t\t\tm_SDWarnTimer.Stop();\n\t\t\tm_SDWarnTimer = null;\n\t\t\tif ( m_SDActivateTimer != null )\n\t\t\t\tm_SDActivateTimer.Stop();\n\t\t\tm_SDActivateTimer = null;\n\t\t}\n\t\tpublic void StartSuddenDeath( TimeSpan timeUntilActive )\n\t\t{\n\t\t\tif ( m_SDWarnTimer != null )\n\t\t\t\tm_SDWarnTimer.Stop();\n\t\t\tm_SDWarnTimer = Timer.DelayCall( TimeSpan.FromMinutes( timeUntilActive.TotalMinutes * 0.9 ), new TimerCallback( WarnSuddenDeath ) );\n\t\t\tif ( m_SDActivateTimer != null )\n\t\t\t\tm_SDActivateTimer.Stop();\n\t\t\tm_SDActivateTimer = Timer.DelayCall( timeUntilActive, new TimerCallback( ActivateSuddenDeath ) );\n\t\t}\n\t\tpublic void WarnSuddenDeath()\n\t\t{\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tfor ( int j = 0; j < p.Players.Length; ++j )\n\t\t\t\t{\n\t\t\t\t\tDuelPlayer pl = p.Players[j];\n\t\t\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tpl.Mobile.SendSound( 0x1E1 );\n\t\t\t\t\tpl.Mobile.SendMessage( 0x22, \"Warning! Warning! Warning!\" );\n\t\t\t\t\tpl.Mobile.SendMessage( 0x22, \"Sudden death will be active soon!\" );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( m_Tournament != null )\n\t\t\t\tm_Tournament.Alert( m_Arena, \"Sudden death will be active soon!\" );\n\t\t\tif ( m_SDWarnTimer != null )\n\t\t\t\tm_SDWarnTimer.Stop();\n\t\t\tm_SDWarnTimer = null;\n\t\t}\n\t\tpublic static bool CheckSuddenDeath( Mobile mob )\n\t\t{\n\t\t\tif ( mob is PlayerMobile )\n\t\t\t{\n\t\t\t\tPlayerMobile pm = (PlayerMobile)mob;\n\t\t\t\tif ( pm.DuelPlayer != null && !pm.DuelPlayer.Eliminated && pm.DuelContext != null && pm.DuelContext.IsSuddenDeath )\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tpublic void ActivateSuddenDeath()\n\t\t{\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tfor ( int j = 0; j < p.Players.Length; ++j )\n\t\t\t\t{\n\t\t\t\t\tDuelPlayer pl = p.Players[j];\n\t\t\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tpl.Mobile.SendSound( 0x1E1 );\n\t\t\t\t\tpl.Mobile.SendMessage( 0x22, \"Warning! Warning! Warning!\" );\n\t\t\t\t\tpl.Mobile.SendMessage( 0x22, \"Sudden death has ACTIVATED. You are now unable to perform any beneficial actions.\" );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( m_Tournament != null )\n\t\t\t\tm_Tournament.Alert( m_Arena, \"Sudden death has been activated!\" );\n\t\t\tm_IsSuddenDeath = true;\n\t\t\tif ( m_SDActivateTimer != null )\n\t\t\t\tm_SDActivateTimer.Stop();\n\t\t\tm_SDActivateTimer = null;\n\t\t}\n\t\tpublic void BeginAutoTie()\n\t\t{\n\t\t\tif ( m_AutoTieTimer != null )\n\t\t\t\tm_AutoTieTimer.Stop();\n\t\t\tTimeSpan ts = ( m_Tournament == null || m_Tournament.TournyType == TournyType.Standard )\n\t\t\t\t? AutoTieDelay\n\t\t\t\t: TimeSpan.FromMinutes( 90.0 );\n\t\t\tm_AutoTieTimer = Timer.DelayCall( ts, new TimerCallback( InvokeAutoTie ) );\n\t\t}\n\t\tpublic void EndAutoTie()\n\t\t{\n\t\t\tif ( m_AutoTieTimer != null )\n\t\t\t\tm_AutoTieTimer.Stop();\n\t\t\tm_AutoTieTimer = null;\n\t\t}\n\t\tpublic void InvokeAutoTie()\n\t\t{\n\t\t\tm_AutoTieTimer = null;\n\t\t\tif ( !m_Started || m_Finished )\n\t\t\t\treturn;\n\t\t\tm_Tied = true;\n\t\t\tm_Finished = true;\n\t\t\tStopSDTimers();\n\t\t\tArrayList remaining = new ArrayList();\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tif ( p.Eliminated )\n\t\t\t\t{\n\t\t\t\t\tp.Broadcast( 0x22, null, p.Players.Length == 1 ? \"{0} has lost the duel.\" : \"{0} and {1} team have lost the duel.\", p.Players.Length == 1 ? \"You have lost the duel.\" : \"Your team has lost the duel.\" );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tp.Broadcast( 0x59, null, p.Players.Length == 1 ? \"{0} has tied the duel due to time expiration.\" : \"{0} and {1} team have tied the duel due to time expiration.\", p.Players.Length == 1 ? \"You have tied the duel due to time expiration.\" : \"Your team has tied the duel due to time expiration.\" );\n\t\t\t\t\tfor ( int j = 0; j < p.Players.Length; ++j )\n\t\t\t\t\t{\n\t\t\t\t\t\tDuelPlayer pl = p.Players[j];\n\t\t\t\t\t\tif ( pl != null && !pl.Eliminated )\n\t\t\t\t\t\t\tDelayBounce( TimeSpan.FromSeconds( 8.0 ), pl.Mobile, null );\n\t\t\t\t\t}\n\t\t\t\t\tif ( p.TournyPart != null )\n\t\t\t\t\t\tremaining.Add( p.TournyPart );\n\t\t\t\t}\n\t\t\t\tfor ( int j = 0; j < p.Players.Length; ++j )\n\t\t\t\t{\n\t\t\t\t\tDuelPlayer pl = p.Players[j];\n\t\t\t\t\tif ( pl != null )\n\t\t\t\t\t{\n\t\t\t\t\t\tpl.Mobile.Delta( MobileDelta.Noto );\n\t\t\t\t\t\tpl.Mobile.SendEverything();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( m_Tournament != null )\n\t\t\t\tm_Tournament.HandleTie( m_Arena, m_Match, remaining );\n\t\t\tTimer.DelayCall( TimeSpan.FromSeconds( 10.0 ), new TimerCallback( Unregister ) );\n\t\t}\n\t\tpublic bool IsOneVsOne\n\t\t{\n\t\t\tget\n\t\t\t{\n\t\t\t\tif ( m_Participants.Count != 2 )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( ((Participant)m_Participants[0]).Players.Length != 1 )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( ((Participant)m_Participants[1]).Players.Length != 1 )\n\t\t\t\t\treturn false;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tpublic static void Initialize()\n\t\t{\n\t\t\tEventSink.Speech += new SpeechEventHandler( EventSink_Speech );\n\t\t\tEventSink.Login += new LoginEventHandler( EventSink_Login );\n\t\t\tCommandSystem.Register( \"vli\", AccessLevel.GameMaster, new CommandEventHandler( vli_oc ) );\n\t\t}\n\t\tprivate static void vli_oc( CommandEventArgs e )\n\t\t{\n\t\t\te.Mobile.BeginTarget( -1, false, Targeting.TargetFlags.None, new TargetCallback( vli_ot ) );\n\t\t}\n\t\tprivate static void vli_ot( Mobile from, object obj )\n\t\t{\n\t\t\tif ( obj is PlayerMobile )\n\t\t\t{\n\t\t\t\tPlayerMobile pm = (PlayerMobile)obj;\n\t\t\t\tLadder ladder = Ladder.Instance;\n\t\t\t\tif ( ladder == null )\n\t\t\t\t\treturn;\n\t\t\t\tLadderEntry entry = ladder.Find( pm );\n\t\t\t\tif ( entry != null )\n\t\t\t\t\tfrom.SendGump( new PropertiesGump( from, entry ) );\n\t\t\t}\n\t\t}\n\t\tprivate static TimeSpan CombatDelay = TimeSpan.FromSeconds( 30.0 );\n\t\tprivate static TimeSpan AutoTieDelay = TimeSpan.FromMinutes( 15.0 );\n\t\tpublic static bool CheckCombat( Mobile m )\n\t\t{\n\t\t\tfor ( int i = 0; i < m.Aggressed.Count; ++i )\n\t\t\t{\n\t\t\t\tAggressorInfo info = m.Aggressed[i];\n\t\t\t\tif ( info.Defender.Player && (DateTime.UtcNow - info.LastCombatTime) < CombatDelay )\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\tfor ( int i = 0; i < m.Aggressors.Count; ++i )\n\t\t\t{\n\t\t\t\tAggressorInfo info = m.Aggressors[i];\n\t\t\t\tif ( info.Attacker.Player && (DateTime.UtcNow - info.LastCombatTime) < CombatDelay )\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tprivate static void EventSink_Login( LoginEventArgs e )\n\t\t{\n\t\t\tPlayerMobile pm = e.Mobile as PlayerMobile;\n\t\t\tif ( pm == null )\n\t\t\t\treturn;\n\t\t\tDuelContext dc = pm.DuelContext;\n\t\t\tif ( dc == null )\n\t\t\t\treturn;\n\t\t\tif ( dc.ReadyWait && pm.DuelPlayer.Ready && !dc.Started && !dc.StartedBeginCountdown && !dc.Finished )\n\t\t\t{\n\t\t\t\tif ( dc.m_Tournament == null )\n\t\t\t\t\tpm.SendGump( new ReadyGump( pm, dc, dc.m_ReadyCount ) );\n\t\t\t}\n\t\t\telse if ( dc.ReadyWait && !dc.StartedBeginCountdown && !dc.Started && !dc.Finished )\n\t\t\t{\n\t\t\t\tif ( dc.m_Tournament == null )\n\t\t\t\t\tpm.SendGump( new ReadyUpGump( pm, dc ) );\n\t\t\t}\n\t\t\telse if ( dc.Initiator == pm && !dc.ReadyWait && !dc.StartedBeginCountdown && !dc.Started && !dc.Finished )\n\t\t\t\tpm.SendGump( new DuelContextGump( pm, dc ) );\n\t\t}\n\t\tprivate static void ViewLadder_OnTarget( Mobile from, object obj, object state )\n\t\t{\n\t\t\tif ( obj is PlayerMobile )\n\t\t\t{\n\t\t\t\tPlayerMobile pm = (PlayerMobile)obj;\n\t\t\t\tLadder ladder = (Ladder)state;\n\t\t\t\tLadderEntry entry = ladder.Find( pm );\n\t\t\t\tif ( entry == null )\n\t\t\t\t\treturn; // sanity\n\t\t\t\tstring text = String.Format( \"{{0}} are ranked {0} at level {1}.\", LadderGump.Rank( entry.Index + 1 ), Ladder.GetLevel( entry.Experience ) );\n\t\t\t\tpm.PrivateOverheadMessage( MessageType.Regular, pm.SpeechHue, true, String.Format( text, from==pm?\"You\":\"They\" ), from.NetState );\n\t\t\t}\n\t\t\telse if ( obj is Mobile )\n\t\t\t{\n\t\t\t\tMobile mob = (Mobile)obj;\n\t\t\t\tif ( mob.Body.IsHuman )\n\t\t\t\t\tmob.PrivateOverheadMessage( MessageType.Regular, mob.SpeechHue, false, \"I'm not a duelist, and quite frankly, I resent the implication.\", from.NetState );\n\t\t\t\telse\n\t\t\t\t\tmob.PrivateOverheadMessage( MessageType.Regular, 0x3B2, true, \"It's probably better than you.\", from.NetState );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfrom.SendMessage( \"That's not a player.\" );\n\t\t\t}\n\t\t}\n\t\tprivate static void EventSink_Speech( SpeechEventArgs e )\n\t\t{\n\t\t\tif ( e.Handled )\n\t\t\t\treturn;\n\t\t\tPlayerMobile pm = e.Mobile as PlayerMobile;\n\t\t\tif ( pm == null )\n\t\t\t\treturn;\n\t\t\tif ( Insensitive.Contains( e.Speech, \"i wish to duel\" ) )\n\t\t\t{\n\t\t\t\tif ( !pm.CheckAlive() )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse if ( pm.Region.IsPartOf( typeof( Regions.Jail ) ) )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse if ( CheckCombat( pm ) )\n\t\t\t\t{\n\t\t\t\t\te.Mobile.SendMessage( 0x22, \"You have recently been in combat with another player and must wait before starting a duel.\" );\n\t\t\t\t}\n\t\t\t\telse if ( pm.DuelContext != null )\n\t\t\t\t{\n\t\t\t\t\tif ( pm.DuelContext.Initiator == pm )\n\t\t\t\t\t\te.Mobile.SendMessage( 0x22, \"You have already started a duel.\" );\n\t\t\t\t\telse\n\t\t\t\t\t\te.Mobile.SendMessage( 0x22, \"You have already been challenged in a duel.\" );\n\t\t\t\t}\n\t\t\t\telse if ( TournamentController.IsActive )\n\t\t\t\t{\n\t\t\t\t\te.Mobile.SendMessage( 0x22, \"You may not start a duel while a tournament is active.\" );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tpm.SendGump( new DuelContextGump( pm, new DuelContext( pm, RulesetLayout.Root ) ) );\n\t\t\t\t\te.Handled = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( Insensitive.Equals( e.Speech, \"change arena preferences\" ) )\n\t\t\t{\n\t\t\t\tif ( !pm.CheckAlive() )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tPreferences prefs = Preferences.Instance;\n\t\t\t\t\tif ( prefs != null )\n\t\t\t\t\t{\n\t\t\t\t\t\te.Mobile.CloseGump( typeof( PreferencesGump ) );\n\t\t\t\t\t\te.Mobile.SendGump( new PreferencesGump( e.Mobile, prefs ) );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( Insensitive.Equals( e.Speech, \"showladder\" ) )\n\t\t\t{\n\t\t\t\te.Blocked=true;\n\t\t\t\tif ( !pm.CheckAlive() )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tLadder instance = Ladder.Instance;\n\t\t\t\t\tif ( instance == null )\n\t\t\t\t\t{\n\t\t\t\t\t\t//pm.SendMessage( \"Ladder not yet initialized.\" );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tLadderEntry entry = instance.Find( pm );\n\t\t\t\t\t\tif ( entry == null )\n\t\t\t\t\t\t\treturn; // sanity\n\t\t\t\t\t\tstring text = String.Format( \"{{0}} {{1}} ranked {0} at level {1}.\", LadderGump.Rank( entry.Index + 1 ), Ladder.GetLevel( entry.Experience ) );\n\t\t\t\t\t\tpm.LocalOverheadMessage( MessageType.Regular, pm.SpeechHue, true, String.Format( text, \"You\", \"are\" ) );\n\t\t\t\t\t\tpm.NonlocalOverheadMessage( MessageType.Regular, pm.SpeechHue, true, String.Format( text, pm.Name, \"is\" ) );\n\t\t\t\t\t\t//pm.PublicOverheadMessage( MessageType.Regular, pm.SpeechHue, true, String.Format( \"Level {0} with {1} win{2} and {3} loss{4}.\", Ladder.GetLevel( entry.Experience ), entry.Wins, entry.Wins==1?\"\":\"s\", entry.Losses, entry.Losses==1?\"\":\"es\" ) );\n\t\t\t\t\t\t//pm.PublicOverheadMessage( MessageType.Regular, pm.SpeechHue, true, String.Format( \"Level {0} with {1} win{2} and {3} loss{4}.\", Ladder.GetLevel( entry.Experience ), entry.Wins, entry.Wins==1?\"\":\"s\", entry.Losses, entry.Losses==1?\"\":\"es\" ) );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( Insensitive.Equals( e.Speech, \"viewladder\" ) )\n\t\t\t{\n\t\t\t\te.Blocked=true;\n\t\t\t\tif ( !pm.CheckAlive() )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tLadder instance = Ladder.Instance;\n\t\t\t\t\tif ( instance == null )\n\t\t\t\t\t{\n\t\t\t\t\t\t//pm.SendMessage( \"Ladder not yet initialized.\" );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tpm.SendMessage( \"Target a player to view their ranking and level.\" );\n\t\t\t\t\t\tpm.BeginTarget( 16, false, Targeting.TargetFlags.None, new TargetStateCallback( ViewLadder_OnTarget ), instance );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( Insensitive.Contains( e.Speech, \"i yield\" ) )\n\t\t\t{\n\t\t\t\tif ( !pm.CheckAlive() )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse if ( pm.DuelContext == null )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse if ( pm.DuelContext.Finished )\n\t\t\t\t{\n\t\t\t\t\te.Mobile.SendMessage( 0x22, \"The duel is already finished.\" );\n\t\t\t\t}\n\t\t\t\telse if ( !pm.DuelContext.Started )\n\t\t\t\t{\n\t\t\t\t\tDuelContext dc = pm.DuelContext;\n\t\t\t\t\tMobile init = dc.Initiator;\n\t\t\t\t\tif ( pm.DuelContext.StartedBeginCountdown )\n\t\t\t\t\t{\n\t\t\t\t\t\te.Mobile.SendMessage( 0x22, \"The duel has not yet started.\" );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tDuelPlayer pl = pm.DuelContext.Find( pm );\n\t\t\t\t\t\tif ( pl == null )\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\tParticipant p = pl.Participant;\n\t\t\t\t\t\tif ( !pm.DuelContext.ReadyWait ) // still setting stuff up\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tp.Broadcast( 0x22, null, \"{0} has yielded.\", \"You have yielded.\" );\n\t\t\t\t\t\t\tif ( init == pm )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdc.Unregister();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tp.Nullify( pl );\n\t\t\t\t\t\t\t\tpm.DuelPlayer=null;\n\t\t\t\t\t\t\t\tNetState ns = init.NetState;\n\t\t\t\t\t\t\t\tif ( ns != null )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tforeach ( Gump g in ns.Gumps )\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tif ( g is ParticipantGump )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tParticipantGump pg = (ParticipantGump)g;\n\t\t\t\t\t\t\t\t\t\t\tif ( pg.Participant == p )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tinit.SendGump( new ParticipantGump( init, dc, p ) );\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse if ( g is DuelContextGump )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tDuelContextGump dcg = (DuelContextGump)g;\n\t\t\t\t\t\t\t\t\t\t\tif ( dcg.Context == dc )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tinit.SendGump( new DuelContextGump( init, dc ) );\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if ( !pm.DuelContext.StartedReadyCountdown ) // at ready stage\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tp.Broadcast( 0x22, null, \"{0} has yielded.\", \"You have yielded.\" );\n\t\t\t\t\t\t\tdc.m_Yielding=true;\n\t\t\t\t\t\t\tdc.RejectReady( pm, null );\n\t\t\t\t\t\t\tdc.m_Yielding=false;\n\t\t\t\t\t\t\tif ( init == pm )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdc.Unregister();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if ( dc.m_Registered )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tp.Nullify( pl );\n\t\t\t\t\t\t\t\tpm.DuelPlayer=null;\n\t\t\t\t\t\t\t\tNetState ns = init.NetState;\n\t\t\t\t\t\t\t\tif ( ns != null )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tbool send=true;\n\t\t\t\t\t\t\t\t\tforeach ( Gump g in ns.Gumps )\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tif ( g is ParticipantGump )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tParticipantGump pg = (ParticipantGump)g;\n\t\t\t\t\t\t\t\t\t\t\tif ( pg.Participant == p )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tinit.SendGump( new ParticipantGump( init, dc, p ) );\n\t\t\t\t\t\t\t\t\t\t\t\tsend=false;\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse if ( g is DuelContextGump )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tDuelContextGump dcg = (DuelContextGump)g;\n\t\t\t\t\t\t\t\t\t\t\tif ( dcg.Context == dc )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tinit.SendGump( new DuelContextGump( init, dc ) );\n\t\t\t\t\t\t\t\t\t\t\t\tsend=false;\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( send )\n\t\t\t\t\t\t\t\t\t\tinit.SendGump( new DuelContextGump( init, dc ) );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif ( pm.DuelContext.m_Countdown != null )\n\t\t\t\t\t\t\t\tpm.DuelContext.m_Countdown.Stop();\n\t\t\t\t\t\t\tpm.DuelContext.m_Countdown= null;\n\t\t\t\t\t\t\tpm.DuelContext.m_StartedReadyCountdown=false;\n\t\t\t\t\t\t\tp.Broadcast( 0x22, null, \"{0} has yielded.\", \"You have yielded.\" );\n\t\t\t\t\t\t\tdc.m_Yielding=true;\n\t\t\t\t\t\t\tdc.RejectReady( pm, null );\n\t\t\t\t\t\t\tdc.m_Yielding=false;\n\t\t\t\t\t\t\tif ( init == pm )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdc.Unregister();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if ( dc.m_Registered )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tp.Nullify( pl );\n\t\t\t\t\t\t\t\tpm.DuelPlayer=null;\n\t\t\t\t\t\t\t\tNetState ns = init.NetState;\n\t\t\t\t\t\t\t\tif ( ns != null )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tbool send=true;\n\t\t\t\t\t\t\t\t\tforeach ( Gump g in ns.Gumps )\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tif ( g is ParticipantGump )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tParticipantGump pg = (ParticipantGump)g;\n\t\t\t\t\t\t\t\t\t\t\tif ( pg.Participant == p )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tinit.SendGump( new ParticipantGump( init, dc, p ) );\n\t\t\t\t\t\t\t\t\t\t\t\tsend=false;\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse if ( g is DuelContextGump )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tDuelContextGump dcg = (DuelContextGump)g;\n\t\t\t\t\t\t\t\t\t\t\tif ( dcg.Context == dc )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tinit.SendGump( new DuelContextGump( init, dc ) );\n\t\t\t\t\t\t\t\t\t\t\t\tsend=false;\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( send )\n\t\t\t\t\t\t\t\t\t\tinit.SendGump( new DuelContextGump( init, dc ) );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tDuelPlayer pl = pm.DuelContext.Find( pm );\n\t\t\t\t\tif ( pl != null )\n\t\t\t\t\t{\n\t\t\t\t\t\tif ( pm.DuelContext.IsOneVsOne )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\te.Mobile.SendMessage( 0x22, \"You may not yield a 1 on 1 match.\" );\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if ( pl.Eliminated )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\te.Mobile.SendMessage( 0x22, \"You have already been eliminated.\" );\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpm.LocalOverheadMessage( MessageType.Regular, 0x22, false, \"You have yielded.\" );\n\t\t\t\t\t\t\tpm.NonlocalOverheadMessage( MessageType.Regular, 0x22, false, String.Format( \"{0} has yielded.\", pm.Name ) );\n\t\t\t\t\t\t\tpm.DuelContext.m_Yielding=true;\n\t\t\t\t\t\t\tpm.Kill();\n\t\t\t\t\t\t\tpm.DuelContext.m_Yielding=false;\n\t\t\t\t\t\t\tif ( pm.Alive ) // invul, ...\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tpl.Eliminated = true;\n\t\t\t\t\t\t\t\tpm.DuelContext.RemoveAggressions( pm );\n\t\t\t\t\t\t\t\tpm.DuelContext.SendOutside( pm );\n\t\t\t\t\t\t\t\tpm.DuelContext.Refresh( pm, null );\n\t\t\t\t\t\t\t\tDebuff( pm );\n\t\t\t\t\t\t\t\tCancelSpell( pm );\n\t\t\t\t\t\t\t\tpm.Frozen = false;\n\t\t\t\t\t\t\t\tParticipant winner = pm.DuelContext.CheckCompletion();\n\t\t\t\t\t\t\t\tif ( winner != null )\n\t\t\t\t\t\t\t\t\tpm.DuelContext.Finish( winner );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\te.Mobile.SendMessage( 0x22, \"BUG: Unable to find duel context.\" );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpublic DuelContext( Mobile initiator, RulesetLayout layout ) : this( initiator, layout, true )\n\t\t{\n\t\t}\n\t\tpublic DuelContext( Mobile initiator, RulesetLayout layout, bool addNew )\n\t\t{\n\t\t\tm_Initiator = initiator;\n\t\t\tm_Participants = new ArrayList();\n\t\t\tm_Ruleset = new Ruleset( layout );\n\t\t\tm_Ruleset.ApplyDefault( layout.Defaults[0] );\n\t\t\tif ( addNew )\n\t\t\t{\n\t\t\t\tm_Participants.Add( new Participant( this, 1 ) );\n\t\t\t\tm_Participants.Add( new Participant( this, 1 ) );\n\t\t\t\t((Participant)m_Participants[0]).Add( initiator );\n\t\t\t}\n\t\t}\n\t\tpublic void CloseAllGumps()\n\t\t{\n\t\t\tType[] types = new Type[]{ typeof( DuelContextGump ), typeof( ParticipantGump ), typeof( RulesetGump ) };\n\t\t\tint[] defs = new int[]{ -1, -1, -1 };\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n", "answers": ["\t\t\t\tParticipant p = (Participant)m_Participants[i];"], "length": 5243, "dataset": "lcc", "language": "csharp", "all_classes": null, "_id": "28ce5cf5e0beeb47248c6cba20ae17fa71d60d402770d464", "answer_prefix": "Next line of code:\n", "task": "lcc", "max_new_tokens": 84}, "target": "['\\t\\t\\t\\tParticipant p = (Participant)m_Participants[i];']", "arguments": {"gen_args_0": {"arg_0": "<|im_start|>user\nPlease complete the code given below. \nPlease complete the code given below. \nusing System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing Server.Commands;\nusing Server.Engines.PartySystem;\nusing Server.Factions;\nusing Server.Gumps;\nusing Server.Items;\nusing Server.Mobiles;\nusing Server.Network;\nusing Server.Spells;\nusing Server.Spells.Bushido;\nusing Server.Spells.Chivalry;\nusing Server.Spells.Necromancy;\nusing Server.Spells.Ninjitsu;\nusing Server.Spells.Seventh;\nusing Server.Spells.Spellweaving;\nnamespace Server.Engines.ConPVP\n{\n public delegate void CountdownCallback( int count );\n\tpublic class DuelContext\n\t{\n\t\tprivate Mobile m_Initiator;\n\t\tprivate ArrayList m_Participants;\n\t\tprivate Ruleset m_Ruleset;\n\t\tprivate Arena m_Arena;\n\t\tprivate bool m_Registered = true;\n\t\tprivate bool m_Finished, m_Started;\n\t\tprivate bool m_ReadyWait;\n\t\tprivate int m_ReadyCount;\n\t\tprivate bool m_Rematch;\n\t\tpublic bool Rematch{ get{ return m_Rematch; } }\n\t\tpublic bool ReadyWait{ get{ return m_ReadyWait; } }\n\t\tpublic int ReadyCount{ get{ return m_ReadyCount; } }\n\t\tpublic bool Registered{ get{ return m_Registered; } }\n\t\tpublic bool Finished{ get{ return m_Finished; } }\n\t\tpublic bool Started{ get{ return m_Started; } }\n\t\tpublic Mobile Initiator{ get{ return m_Initiator; } }\n\t\tpublic ArrayList Participants{ get{ return m_Participants; } }\n\t\tpublic Ruleset Ruleset{ get{ return m_Ruleset; } }\n\t\tpublic Arena Arena{ get{ return m_Arena; } }\n\t\tprivate bool CantDoAnything( Mobile mob )\n\t\t{\n\t\t\tif ( m_EventGame != null )\n\t\t\t\treturn m_EventGame.CantDoAnything( mob );\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\t\tpublic static bool IsFreeConsume( Mobile mob )\n\t\t{\n\t\t\tPlayerMobile pm = mob as PlayerMobile;\n\t\t\tif ( pm == null || pm.DuelContext == null || pm.DuelContext.m_EventGame == null )\n\t\t\t\treturn false;\n\t\t\treturn pm.DuelContext.m_EventGame.FreeConsume;\n\t\t}\n\t\tpublic void DelayBounce( TimeSpan ts, Mobile mob, Container corpse )\n\t\t{\n\t\t\tTimer.DelayCall( ts, new TimerStateCallback( DelayBounce_Callback ), new object[]{ mob, corpse } );\n\t\t}\n\t\tpublic static bool AllowSpecialMove( Mobile from, string name, SpecialMove move )\n\t\t{\n\t\t\tPlayerMobile pm = from as PlayerMobile;\n\t\t\tif( pm == null )\n\t\t\t\treturn true;\n\t\t\tDuelContext dc = pm.DuelContext;\n\t\t\treturn (dc == null || dc.InstAllowSpecialMove( from, name, move ));\n\t\t}\n\t\tpublic bool InstAllowSpecialMove( Mobile from, string name, SpecialMove move )\n\t\t{\n\t\t\tif ( !m_StartedBeginCountdown )\n\t\t\t\treturn true;\n\t\t\tDuelPlayer pl = Find( from );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn true;\n\t\t\tif ( CantDoAnything( from ) )\n\t\t\t\treturn false;\n\t\t\tstring title = null;\n\t\t\tif( move is NinjaMove )\n\t\t\t\ttitle = \"Bushido\";\n\t\t\telse if( move is SamuraiMove )\n\t\t\t\ttitle = \"Ninjitsu\";\n\t\t\tif ( title == null || name == null || m_Ruleset.GetOption( title, name ) )\n\t\t\t\treturn true;\n\t\t\tfrom.SendMessage( \"The dueling ruleset prevents you from using this move.\" );\n\t\t\treturn false;\n\t\t}\n\t\tpublic bool AllowSpellCast( Mobile from, Spell spell )\n\t\t{\n\t\t\tif ( !m_StartedBeginCountdown )\n\t\t\t\treturn true;\n\t\t\tDuelPlayer pl = Find( from );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn true;\n\t\t\tif ( CantDoAnything( from ) )\n\t\t\t\treturn false;\n\t\t\tif ( spell is Server.Spells.Fourth.RecallSpell )\n\t\t\t\tfrom.SendMessage( \"You may not cast this spell.\" );\n\t\t\tstring title = null, option = null;\n\t\t\tif( spell is ArcanistSpell )\n\t\t\t{\n\t\t\t\ttitle = \"Spellweaving\";\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\telse if ( spell is PaladinSpell )\n\t\t\t{\n\t\t\t\ttitle = \"Chivalry\";\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\telse if ( spell is NecromancerSpell )\n\t\t\t{\n\t\t\t\ttitle = \"Necromancy\";\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\telse if ( spell is NinjaSpell )\n\t\t\t{\n\t\t\t\ttitle = \"Ninjitsu\";\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\telse if ( spell is SamuraiSpell )\n\t\t\t{\n\t\t\t\ttitle = \"Bushido\";\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\telse if( spell is MagerySpell )\n\t\t\t{\n\t\t\t\tswitch( ((MagerySpell)spell).Circle )\n\t\t\t\t{\n\t\t\t\t\tcase SpellCircle.First: title = \"1st Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Second: title = \"2nd Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Third: title = \"3rd Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Fourth: title = \"4th Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Fifth: title = \"5th Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Sixth: title = \"6th Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Seventh: title = \"7th Circle\"; break;\n\t\t\t\t\tcase SpellCircle.Eighth: title = \"8th Circle\"; break;\n\t\t\t\t}\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ttitle = \"Other Spell\";\n\t\t\t\toption = spell.Name;\n\t\t\t}\n\t\t\tif ( title == null || option == null || m_Ruleset.GetOption( title, option ) )\n\t\t\t\treturn true;\n\t\t\tfrom.SendMessage( \"The dueling ruleset prevents you from casting this spell.\" );\n\t\t\treturn false;\n\t\t}\n\t\tpublic bool AllowItemEquip( Mobile from, Item item )\n\t\t{\n\t\t\tif ( !m_StartedBeginCountdown )\n\t\t\t\treturn true;\n\t\t\tDuelPlayer pl = Find( from );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn true;\n\t\t\tif ( item is Dagger || CheckItemEquip( from, item ) )\n\t\t\t\treturn true;\n\t\t\tfrom.SendMessage( \"The dueling ruleset prevents you from equiping this item.\" );\n\t\t\treturn false;\n\t\t}\n\t\tpublic static bool AllowSpecialAbility( Mobile from, string name, bool message )\n\t\t{\n\t\t\tPlayerMobile pm = from as PlayerMobile;\n\t\t\tif ( pm == null )\n\t\t\t\treturn true;\n\t\t\tDuelContext dc = pm.DuelContext;\n\t\t\treturn ( dc == null || dc.InstAllowSpecialAbility( from, name, message ) );\n\t\t}\n\t\tpublic bool InstAllowSpecialAbility( Mobile from, string name, bool message )\n\t\t{\n\t\t\tif ( !m_StartedBeginCountdown )\n\t\t\t\treturn true;\n\t\t\tDuelPlayer pl = Find( from );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn true;\n\t\t\tif ( CantDoAnything( from ) )\n\t\t\t\treturn false;\n\t\t\tif ( m_Ruleset.GetOption( \"Combat Abilities\", name ) )\n\t\t\t\treturn true;\n\t\t\tif ( message )\n\t\t\t\tfrom.SendMessage( \"The dueling ruleset prevents you from using this combat ability.\" );\n\t\t\treturn false;\n\t\t}\n\t\tpublic bool CheckItemEquip( Mobile from, Item item )\n\t\t{\n\t\t\tif ( item is Fists )\n\t\t\t{\n\t\t\t\tif ( !m_Ruleset.GetOption( \"Weapons\", \"Wrestling\" ) )\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse if ( item is BaseArmor )\n\t\t\t{\n\t\t\t\tBaseArmor armor = (BaseArmor)item;\n\t\t\t\tif ( armor.ProtectionLevel > ArmorProtectionLevel.Regular && !m_Ruleset.GetOption( \"Armor\", \"Magical\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( !Core.AOS && armor.Resource != armor.DefaultResource && !m_Ruleset.GetOption( \"Armor\", \"Colored\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( armor is BaseShield && !m_Ruleset.GetOption( \"Armor\", \"Shields\" ) )\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse if ( item is BaseWeapon )\n\t\t\t{\n\t\t\t\tBaseWeapon weapon = (BaseWeapon)item;\n\t\t\t\tif ( (weapon.DamageLevel > WeaponDamageLevel.Regular || weapon.AccuracyLevel > WeaponAccuracyLevel.Regular) && !m_Ruleset.GetOption( \"Weapons\", \"Magical\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( !Core.AOS && weapon.Resource != CraftResource.Iron && weapon.Resource != CraftResource.None && !m_Ruleset.GetOption( \"Weapons\", \"Runics\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( weapon is BaseRanged && !m_Ruleset.GetOption( \"Weapons\", \"Ranged\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( !(weapon is BaseRanged) && !m_Ruleset.GetOption( \"Weapons\", \"Melee\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( weapon.PoisonCharges > 0 && weapon.Poison != null && !m_Ruleset.GetOption( \"Weapons\", \"Poisoned\" ) )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( weapon is BaseWand && !m_Ruleset.GetOption( \"Items\", \"Wands\" ) )\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tpublic bool AllowSkillUse( Mobile from, SkillName skill )\n\t\t{\n\t\t\tif ( !m_StartedBeginCountdown )\n\t\t\t\treturn true;\n\t\t\tDuelPlayer pl = Find( from );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn true;\n\t\t\tif ( CantDoAnything( from ) )\n\t\t\t\treturn false;\n\t\t\tint id = (int)skill;\n\t\t\tif ( id >= 0 && id < SkillInfo.Table.Length )\n\t\t\t{\n\t\t\t\tif ( m_Ruleset.GetOption( \"Skills\", SkillInfo.Table[id].Name ) )\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\tfrom.SendMessage( \"The dueling ruleset prevents you from using this skill.\" );\n\t\t\treturn false;\n\t\t}\n\t\tpublic bool AllowItemUse( Mobile from, Item item )\n\t\t{\n\t\t\tif ( !m_StartedBeginCountdown )\n\t\t\t\treturn true;\n\t\t\tDuelPlayer pl = Find( from );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn true;\n\t\t\tif ( !(item is BaseRefreshPotion) )\n\t\t\t{\n\t\t\t\tif ( CantDoAnything( from ) )\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\tstring title = null, option = null;\n\t\t\tif ( item is BasePotion )\n\t\t\t{\n\t\t\t\ttitle = \"Potions\";\n\t\t\t\tif ( item is BaseAgilityPotion )\n\t\t\t\t\toption = \"Agility\";\n\t\t\t\telse if ( item is BaseCurePotion )\n\t\t\t\t\toption = \"Cure\";\n\t\t\t\telse if ( item is BaseHealPotion )\n\t\t\t\t\toption = \"Heal\";\n\t\t\t\telse if ( item is NightSightPotion )\n\t\t\t\t\toption = \"Nightsight\";\n\t\t\t\telse if ( item is BasePoisonPotion )\n\t\t\t\t\toption = \"Poison\";\n\t\t\t\telse if ( item is BaseStrengthPotion )\n\t\t\t\t\toption = \"Strength\";\n\t\t\t\telse if ( item is BaseExplosionPotion )\n\t\t\t\t\toption = \"Explosion\";\n\t\t\t\telse if ( item is BaseRefreshPotion )\n\t\t\t\t\toption = \"Refresh\";\n\t\t\t}\n\t\t\telse if ( item is Bandage )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Bandages\";\n\t\t\t}\n\t\t\telse if ( item is TrapableContainer )\n\t\t\t{\n\t\t\t\tif ( ((TrapableContainer)item).TrapType != TrapType.None )\n\t\t\t\t{\n\t\t\t\t\ttitle = \"Items\";\n\t\t\t\t\toption = \"Trapped Containers\";\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( item is Bola )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Bolas\";\n\t\t\t}\n\t\t\telse if ( item is OrangePetals )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Orange Petals\";\n\t\t\t}\n\t\t\telse if ( item is EtherealMount || item.Layer == Layer.Mount )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Mounts\";\n\t\t\t}\n\t\t\telse if ( item is LeatherNinjaBelt )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Shurikens\";\n\t\t\t}\n\t\t\telse if ( item is Fukiya )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Fukiya Darts\";\n\t\t\t}\n\t\t\telse if ( item is FireHorn )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Fire Horns\";\n\t\t\t}\n\t\t\telse if ( item is BaseWand )\n\t\t\t{\n\t\t\t\ttitle = \"Items\";\n\t\t\t\toption = \"Wands\";\n\t\t\t}\n\t\t\tif ( title != null && option != null && m_StartedBeginCountdown && !m_Started )\n\t\t\t{\n\t\t\t\tfrom.SendMessage( \"You may not use this item before the duel begins.\" );\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse if ( item is BasePotion && !(item is BaseExplosionPotion) && !(item is BaseRefreshPotion) && IsSuddenDeath )\n\t\t\t{\n\t\t\t\tfrom.SendMessage( 0x22, \"You may not drink potions in sudden death.\" );\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse if ( item is Bandage && IsSuddenDeath )\n\t\t\t{\n\t\t\t\tfrom.SendMessage( 0x22, \"You may not use bandages in sudden death.\" );\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif ( title == null || option == null || m_Ruleset.GetOption( title, option ) )\n\t\t\t\treturn true;\n\t\t\tfrom.SendMessage( \"The dueling ruleset prevents you from using this item.\" );\n\t\t\treturn false;\n\t\t}\n\t\tprivate void DelayBounce_Callback( object state )\n\t\t{\n\t\t\tobject[] states = (object[])state;\n\t\t\tMobile mob = (Mobile) states[0];\n\t\t\tContainer corpse = (Container) states[1];\n\t\t\tRemoveAggressions( mob );\n\t\t\tSendOutside( mob );\n\t\t\tRefresh( mob, corpse );\n\t\t\tDebuff( mob );\n\t\t\tCancelSpell( mob );\n\t\t\tmob.Frozen = false;\n\t\t}\n\t\tpublic void OnMapChanged( Mobile mob )\n\t\t{\n\t\t\tOnLocationChanged( mob );\n\t\t}\n\t\tpublic void OnLocationChanged( Mobile mob )\n\t\t{\n\t\t\tif ( !m_Registered || !m_StartedBeginCountdown || m_Finished )\n\t\t\t\treturn;\n\t\t\tArena arena = m_Arena;\n\t\t\tif ( arena == null )\n\t\t\t\treturn;\n\t\t\tif ( mob.Map == arena.Facet && arena.Bounds.Contains( mob.Location ) )\n\t\t\t\treturn;\n\t\t\tDuelPlayer pl = Find( mob );\n\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\treturn;\n\t\t\tif ( mob.Map == Map.Internal ) {\n\t\t\t\t// they've logged out\n\t\t\t\tif ( mob.LogoutMap == arena.Facet && arena.Bounds.Contains( mob.LogoutLocation ) ) {\n\t\t\t\t\t// they logged out inside the arena.. set them to eject on login\n\t\t\t\t\tmob.LogoutLocation = arena.Outside;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpl.Eliminated = true;\n\t\t\tmob.LocalOverheadMessage( MessageType.Regular, 0x22, false, \"You have forfeited your position in the duel.\" );\n\t\t\tmob.NonlocalOverheadMessage( MessageType.Regular, 0x22, false, String.Format( \"{0} has forfeited by leaving the dueling arena.\", mob.Name ) );\n\t\t\tParticipant winner = CheckCompletion();\n\t\t\tif ( winner != null )\n\t\t\t\tFinish( winner );\n\t\t}\n\t\tprivate bool m_Yielding;\n\t\tpublic void OnDeath( Mobile mob, Container corpse )\n\t\t{\n\t\t\tif ( !m_Registered || !m_Started )\n\t\t\t\treturn;\n\t\t\tDuelPlayer pl = Find( mob );\n\t\t\tif ( pl != null && !pl.Eliminated )\n\t\t\t{\n\t\t\t\tif ( m_EventGame != null && !m_EventGame.OnDeath( mob, corpse ) )\n\t\t\t\t\treturn;\n\t\t\t\tpl.Eliminated = true;\n\t\t\t\tif ( mob.Poison != null )\n\t\t\t\t\tmob.Poison = null;\n\t\t\t\tRequip( mob, corpse );\n\t\t\t\tDelayBounce( TimeSpan.FromSeconds( 4.0 ), mob, corpse );\n\t\t\t\tParticipant winner = CheckCompletion();\n\t\t\t\tif ( winner != null )\n\t\t\t\t{\n\t\t\t\t\tFinish( winner );\n\t\t\t\t}\n\t\t\t\telse if ( !m_Yielding )\n\t\t\t\t{\n\t\t\t\t\tmob.LocalOverheadMessage( MessageType.Regular, 0x22, false, \"You have been defeated.\" );\n\t\t\t\t\tmob.NonlocalOverheadMessage( MessageType.Regular, 0x22, false, String.Format( \"{0} has been defeated.\", mob.Name ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpublic bool CheckFull()\n\t\t{\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tif ( p.HasOpenSlot )\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tpublic void Requip( Mobile from, Container cont )\n\t\t{\n\t\t\tCorpse corpse = cont as Corpse;\n\t\t\tif ( corpse == null )\n\t\t\t\treturn;\n\t\t\tList<Item> items = new List<Item>( corpse.Items );\n\t\t\tbool gathered = false;\n\t\t\tbool didntFit = false;\n\t\t\tContainer pack = from.Backpack;\n\t\t\tfor ( int i = 0; !didntFit && i < items.Count; ++i )\n\t\t\t{\n\t\t\t\tItem item = items[i];\n\t\t\t\tPoint3D loc = item.Location;\n\t\t\t\tif ( (item.Layer == Layer.Hair || item.Layer == Layer.FacialHair) || !item.Movable )\n\t\t\t\t\tcontinue;\n\t\t\t\tif ( pack != null )\n\t\t\t\t{\n\t\t\t\t\tpack.DropItem( item );\n\t\t\t\t\tgathered = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tdidntFit = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcorpse.Carved = true;\n\t\t\tif ( corpse.ItemID == 0x2006 )\n\t\t\t{\n\t\t\t\tcorpse.ProcessDelta();\n\t\t\t\tcorpse.SendRemovePacket();\n\t\t\t\tcorpse.ItemID = Utility.Random( 0xECA, 9 ); // bone graphic\n\t\t\t\tcorpse.Hue = 0;\n\t\t\t\tcorpse.ProcessDelta();\n\t\t\t\tMobile killer = from.FindMostRecentDamager( false );\n\t\t\t\tif ( killer != null && killer.Player )\n\t\t\t\t\tkiller.AddToBackpack( new Head( m_Tournament == null ? HeadType.Duel : HeadType.Tournament, from.Name ) );\n\t\t\t}\n\t\t\tfrom.PlaySound( 0x3E3 );\n\t\t\tif ( gathered && !didntFit )\n\t\t\t\tfrom.SendLocalizedMessage( 1062471 ); // You quickly gather all of your belongings.\n\t\t\telse if ( gathered && didntFit )\n\t\t\t\tfrom.SendLocalizedMessage( 1062472 ); // You gather some of your belongings. The rest remain on the corpse.\n\t\t}\n\t\tpublic void Refresh( Mobile mob, Container cont )\n\t\t{\n\t\t\tif ( !mob.Alive )\n\t\t\t{\n\t\t\t\tmob.Resurrect();\n\t\t\t\tDeathRobe robe = mob.FindItemOnLayer( Layer.OuterTorso ) as DeathRobe;\n\t\t\t\tif ( robe != null )\n\t\t\t\t\trobe.Delete();\n\t\t\t\tif ( cont is Corpse )\n\t\t\t\t{\n\t\t\t\t\tCorpse corpse = (Corpse) cont;\n\t\t\t\t\tfor ( int i = 0; i < corpse.EquipItems.Count; ++i )\n\t\t\t\t\t{\n\t\t\t\t\t\tItem item = corpse.EquipItems[i];\n\t\t\t\t\t\tif ( item.Movable && item.Layer != Layer.Hair && item.Layer != Layer.FacialHair && item.IsChildOf( mob.Backpack ) )\n\t\t\t\t\t\t\tmob.EquipItem( item );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tmob.Hits = mob.HitsMax;\n\t\t\tmob.Stam = mob.StamMax;\n\t\t\tmob.Mana = mob.ManaMax;\n\t\t\tmob.Poison = null;\n\t\t}\n\t\tpublic void SendOutside( Mobile mob )\n\t\t{\n\t\t\tif ( m_Arena == null )\n\t\t\t\treturn;\n\t\t\tmob.Combatant = null;\n\t\t\tmob.MoveToWorld( m_Arena.Outside, m_Arena.Facet );\n\t\t}\n\t\tprivate Point3D m_GatePoint;\n\t\tprivate Map m_GateFacet;\n\t\tpublic void Finish( Participant winner )\n\t\t{\n\t\t\tif ( m_Finished )\n\t\t\t\treturn;\n\t\t\tEndAutoTie();\n\t\t\tStopSDTimers();\n\t\t\tm_Finished = true;\n\t\t\tfor ( int i = 0; i < winner.Players.Length; ++i )\n\t\t\t{\n\t\t\t\tDuelPlayer pl = winner.Players[i];\n\t\t\t\tif ( pl != null && !pl.Eliminated )\n\t\t\t\t\tDelayBounce( TimeSpan.FromSeconds( 8.0 ), pl.Mobile, null );\n\t\t\t}\n\t\t\twinner.Broadcast( 0x59, null, winner.Players.Length == 1 ? \"{0} has won the duel.\" : \"{0} and {1} team have won the duel.\", winner.Players.Length == 1 ? \"You have won the duel.\" : \"Your team has won the duel.\" );\n\t\t\tif ( m_Tournament != null && winner.TournyPart != null )\n\t\t\t{\n\t\t\t\tm_Match.Winner = winner.TournyPart;\n\t\t\t\twinner.TournyPart.WonMatch( m_Match );\n\t\t\t\tm_Tournament.HandleWon( m_Arena, m_Match, winner.TournyPart );\n\t\t\t}\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant loser = (Participant)m_Participants[i];\n\t\t\t\tif ( loser != winner )\n\t\t\t\t{\n\t\t\t\t\tloser.Broadcast( 0x22, null, loser.Players.Length == 1 ? \"{0} has lost the duel.\" : \"{0} and {1} team have lost the duel.\", loser.Players.Length == 1 ? \"You have lost the duel.\" : \"Your team has lost the duel.\" );\n\t\t\t\t\tif ( m_Tournament != null && loser.TournyPart != null )\n\t\t\t\t\t\tloser.TournyPart.LostMatch( m_Match );\n\t\t\t\t}\n\t\t\t\tfor ( int j = 0; j < loser.Players.Length; ++j )\n\t\t\t\t{\n\t\t\t\t\tif ( loser.Players[j] != null )\n\t\t\t\t\t{\n\t\t\t\t\t\tRemoveAggressions( loser.Players[j].Mobile );\n\t\t\t\t\t\tloser.Players[j].Mobile.Delta( MobileDelta.Noto );\n\t\t\t\t\t\tloser.Players[j].Mobile.CloseGump( typeof( BeginGump ) );\n\t\t\t\t\t\tif ( m_Tournament != null )\n\t\t\t\t\t\t\tloser.Players[j].Mobile.SendEverything();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( IsOneVsOne )\n\t\t\t{\n\t\t\t\tDuelPlayer dp1 = ((Participant)m_Participants[0]).Players[0];\n\t\t\t\tDuelPlayer dp2 = ((Participant)m_Participants[1]).Players[0];\n\t\t\t\tif ( dp1 != null && dp2 != null )\n\t\t\t\t{\n\t\t\t\t\tAward( dp1.Mobile, dp2.Mobile, dp1.Participant == winner );\n\t\t\t\t\tAward( dp2.Mobile, dp1.Mobile, dp2.Participant == winner );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( m_EventGame != null )\n\t\t\t\tm_EventGame.OnStop();\n\t\t\tTimer.DelayCall( TimeSpan.FromSeconds( 9.0 ), new TimerCallback( UnregisterRematch ) );\n\t\t}\n\t\tpublic void Award( Mobile us, Mobile them, bool won )\n\t\t{\n\t\t\tLadder ladder = ( m_Arena == null ? Ladder.Instance : m_Arena.AcquireLadder() );\n\t\t\tif ( ladder == null )\n\t\t\t\treturn;\n\t\t\tLadderEntry ourEntry = ladder.Find( us );\n\t\t\tLadderEntry theirEntry = ladder.Find( them );\n\t\t\tif ( ourEntry == null || theirEntry == null )\n\t\t\t\treturn;\n\t\t\tint xpGain = Ladder.GetExperienceGain( ourEntry, theirEntry, won );\n\t\t\tif ( xpGain == 0 )\n\t\t\t\treturn;\n\t\t\tif ( m_Tournament != null )\n\t\t\t\txpGain *= ( xpGain > 0 ? 5 : 2 );\n\t\t\tif ( won )\n\t\t\t\t++ourEntry.Wins;\n\t\t\telse\n\t\t\t\t++ourEntry.Losses;\n\t\t\tint oldLevel = Ladder.GetLevel( ourEntry.Experience );\n\t\t\tourEntry.Experience += xpGain;\n\t\t\tif ( ourEntry.Experience < 0 )\n\t\t\t\tourEntry.Experience = 0;\n\t\t\tladder.UpdateEntry( ourEntry );\n\t\t\tint newLevel = Ladder.GetLevel( ourEntry.Experience );\n\t\t\tif ( newLevel > oldLevel )\n\t\t\t\tus.SendMessage( 0x59, \"You have achieved level {0}!\", newLevel );\n\t\t\telse if ( newLevel < oldLevel )\n\t\t\t\tus.SendMessage( 0x22, \"You have lost a level. You are now at {0}.\", newLevel );\n\t\t}\n\t\tpublic void UnregisterRematch()\n\t\t{\n\t\t\tUnregister(true);\n\t\t}\n\t\tpublic void Unregister()\n\t\t{\n\t\t\tUnregister(false);\n\t\t}\n\t\tpublic void Unregister( bool queryRematch )\n\t\t{\n\t\t\tDestroyWall();\n\t\t\tif ( !m_Registered )\n\t\t\t\treturn;\n\t\t\tm_Registered = false;\n\t\t\tif ( m_Arena != null )\n\t\t\t\tm_Arena.Evict();\n\t\t\tStopSDTimers();\n\t\t\tType[] types = new Type[]{ typeof( BeginGump ), typeof( DuelContextGump ), typeof( ParticipantGump ), typeof( PickRulesetGump ), typeof( ReadyGump ), typeof( ReadyUpGump ), typeof( RulesetGump ) };\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tfor ( int j = 0; j < p.Players.Length; ++j )\n\t\t\t\t{\n\t\t\t\t\tDuelPlayer pl = (DuelPlayer)p.Players[j];\n\t\t\t\t\tif ( pl == null )\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tif ( pl.Mobile is PlayerMobile )\n\t\t\t\t\t\t((PlayerMobile)pl.Mobile).DuelPlayer = null;\n\t\t\t\t\tfor ( int k = 0; k < types.Length; ++k )\n\t\t\t\t\t\tpl.Mobile.CloseGump( types[k] );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( queryRematch && m_Tournament == null )\n\t\t\t\tQueryRematch();\n\t\t}\n\t\tpublic void QueryRematch()\n\t\t{\n\t\t\tDuelContext dc = new DuelContext( m_Initiator, m_Ruleset.Layout, false );\n\t\t\tdc.m_Ruleset = m_Ruleset;\n\t\t\tdc.m_Rematch = true;\n\t\t\tdc.m_Participants.Clear();\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant oldPart = (Participant)m_Participants[i];\n\t\t\t\tParticipant newPart = new Participant( dc, oldPart.Players.Length );\n\t\t\t\tfor ( int j = 0; j < oldPart.Players.Length; ++j )\n\t\t\t\t{\n\t\t\t\t\tDuelPlayer oldPlayer = oldPart.Players[j];\n\t\t\t\t\tif ( oldPlayer != null )\n\t\t\t\t\t\tnewPart.Players[j] = new DuelPlayer( oldPlayer.Mobile, newPart );\n\t\t\t\t}\n\t\t\t\tdc.m_Participants.Add( newPart );\n\t\t\t}\n\t\t\tdc.CloseAllGumps();\n\t\t\tdc.SendReadyUpGump();\n\t\t}\n\t\tpublic DuelPlayer Find( Mobile mob )\n\t\t{\n\t\t\tif ( mob is PlayerMobile )\n\t\t\t{\n\t\t\t\tPlayerMobile pm = (PlayerMobile)mob;\n\t\t\t\tif ( pm.DuelContext == this )\n\t\t\t\t\treturn pm.DuelPlayer;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tDuelPlayer pl = p.Find( mob );\n\t\t\t\tif ( pl != null )\n\t\t\t\t\treturn pl;\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\t\tpublic bool IsAlly( Mobile m1, Mobile m2 )\n\t\t{\n\t\t\tDuelPlayer pl1 = Find( m1 );\n\t\t\tDuelPlayer pl2 = Find( m2 );\n\t\t\treturn ( pl1 != null && pl2 != null && pl1.Participant == pl2.Participant );\n\t\t}\n\t\tpublic Participant CheckCompletion()\n\t\t{\n\t\t\tParticipant winner = null;\n\t\t\tbool hasWinner = false;\n\t\t\tint eliminated = 0;\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tif ( p.Eliminated )\n\t\t\t\t{\n\t\t\t\t\t++eliminated;\n\t\t\t\t\tif ( eliminated == (m_Participants.Count - 1) )\n\t\t\t\t\t\thasWinner = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\twinner = p;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( hasWinner )\n\t\t\t\treturn winner == null ? (Participant) m_Participants[0] : winner;\n\t\t\treturn null;\n\t\t}\n\t\tprivate Timer m_Countdown;\n\t\tpublic void StartCountdown( int count, CountdownCallback cb )\n\t\t{\n\t\t\tcb(count);\n\t\t\tm_Countdown=Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), TimeSpan.FromSeconds( 1.0 ), count, new TimerStateCallback( Countdown_Callback ), new object[]{ count-1, cb } );\n\t\t}\n\t\tpublic void StopCountdown()\n\t\t{\n\t\t\tif ( m_Countdown != null )\n\t\t\t\tm_Countdown.Stop();\n\t\t\tm_Countdown = null;\n\t\t}\n\t\tprivate void Countdown_Callback( object state )\n\t\t{\n\t\t\tobject[] states = (object[])state;\n\t\t\tint count = (int)states[0];\n\t\t\tCountdownCallback cb = (CountdownCallback)states[1];\n\t\t\tif ( count==0 )\n\t\t\t{\n\t\t\t\tif ( m_Countdown != null )\n\t\t\t\t\tm_Countdown.Stop();\n\t\t\t\tm_Countdown=null;\n\t\t\t}\n\t\t\tcb( count );\n\t\t\tstates[0] = count - 1;\n\t\t}\n\t\tprivate Timer m_AutoTieTimer;\n\t\tprivate bool m_Tied;\n\t\tpublic bool Tied{ get{ return m_Tied; } }\n\t\tprivate bool m_IsSuddenDeath;\n\t\tpublic bool IsSuddenDeath{ get{ return m_IsSuddenDeath; } set{ m_IsSuddenDeath = value; } }\n\t\tprivate Timer m_SDWarnTimer, m_SDActivateTimer;\n\t\tpublic void StopSDTimers()\n\t\t{\n\t\t\tif ( m_SDWarnTimer != null )\n\t\t\t\tm_SDWarnTimer.Stop();\n\t\t\tm_SDWarnTimer = null;\n\t\t\tif ( m_SDActivateTimer != null )\n\t\t\t\tm_SDActivateTimer.Stop();\n\t\t\tm_SDActivateTimer = null;\n\t\t}\n\t\tpublic void StartSuddenDeath( TimeSpan timeUntilActive )\n\t\t{\n\t\t\tif ( m_SDWarnTimer != null )\n\t\t\t\tm_SDWarnTimer.Stop();\n\t\t\tm_SDWarnTimer = Timer.DelayCall( TimeSpan.FromMinutes( timeUntilActive.TotalMinutes * 0.9 ), new TimerCallback( WarnSuddenDeath ) );\n\t\t\tif ( m_SDActivateTimer != null )\n\t\t\t\tm_SDActivateTimer.Stop();\n\t\t\tm_SDActivateTimer = Timer.DelayCall( timeUntilActive, new TimerCallback( ActivateSuddenDeath ) );\n\t\t}\n\t\tpublic void WarnSuddenDeath()\n\t\t{\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tfor ( int j = 0; j < p.Players.Length; ++j )\n\t\t\t\t{\n\t\t\t\t\tDuelPlayer pl = p.Players[j];\n\t\t\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tpl.Mobile.SendSound( 0x1E1 );\n\t\t\t\t\tpl.Mobile.SendMessage( 0x22, \"Warning! Warning! Warning!\" );\n\t\t\t\t\tpl.Mobile.SendMessage( 0x22, \"Sudden death will be active soon!\" );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( m_Tournament != null )\n\t\t\t\tm_Tournament.Alert( m_Arena, \"Sudden death will be active soon!\" );\n\t\t\tif ( m_SDWarnTimer != null )\n\t\t\t\tm_SDWarnTimer.Stop();\n\t\t\tm_SDWarnTimer = null;\n\t\t}\n\t\tpublic static bool CheckSuddenDeath( Mobile mob )\n\t\t{\n\t\t\tif ( mob is PlayerMobile )\n\t\t\t{\n\t\t\t\tPlayerMobile pm = (PlayerMobile)mob;\n\t\t\t\tif ( pm.DuelPlayer != null && !pm.DuelPlayer.Eliminated && pm.DuelContext != null && pm.DuelContext.IsSuddenDeath )\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tpublic void ActivateSuddenDeath()\n\t\t{\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tfor ( int j = 0; j < p.Players.Length; ++j )\n\t\t\t\t{\n\t\t\t\t\tDuelPlayer pl = p.Players[j];\n\t\t\t\t\tif ( pl == null || pl.Eliminated )\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tpl.Mobile.SendSound( 0x1E1 );\n\t\t\t\t\tpl.Mobile.SendMessage( 0x22, \"Warning! Warning! Warning!\" );\n\t\t\t\t\tpl.Mobile.SendMessage( 0x22, \"Sudden death has ACTIVATED. You are now unable to perform any beneficial actions.\" );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( m_Tournament != null )\n\t\t\t\tm_Tournament.Alert( m_Arena, \"Sudden death has been activated!\" );\n\t\t\tm_IsSuddenDeath = true;\n\t\t\tif ( m_SDActivateTimer != null )\n\t\t\t\tm_SDActivateTimer.Stop();\n\t\t\tm_SDActivateTimer = null;\n\t\t}\n\t\tpublic void BeginAutoTie()\n\t\t{\n\t\t\tif ( m_AutoTieTimer != null )\n\t\t\t\tm_AutoTieTimer.Stop();\n\t\t\tTimeSpan ts = ( m_Tournament == null || m_Tournament.TournyType == TournyType.Standard )\n\t\t\t\t? AutoTieDelay\n\t\t\t\t: TimeSpan.FromMinutes( 90.0 );\n\t\t\tm_AutoTieTimer = Timer.DelayCall( ts, new TimerCallback( InvokeAutoTie ) );\n\t\t}\n\t\tpublic void EndAutoTie()\n\t\t{\n\t\t\tif ( m_AutoTieTimer != null )\n\t\t\t\tm_AutoTieTimer.Stop();\n\t\t\tm_AutoTieTimer = null;\n\t\t}\n\t\tpublic void InvokeAutoTie()\n\t\t{\n\t\t\tm_AutoTieTimer = null;\n\t\t\tif ( !m_Started || m_Finished )\n\t\t\t\treturn;\n\t\t\tm_Tied = true;\n\t\t\tm_Finished = true;\n\t\t\tStopSDTimers();\n\t\t\tArrayList remaining = new ArrayList();\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\n\t\t\t\tParticipant p = (Participant)m_Participants[i];\n\t\t\t\tif ( p.Eliminated )\n\t\t\t\t{\n\t\t\t\t\tp.Broadcast( 0x22, null, p.Players.Length == 1 ? \"{0} has lost the duel.\" : \"{0} and {1} team have lost the duel.\", p.Players.Length == 1 ? \"You have lost the duel.\" : \"Your team has lost the duel.\" );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tp.Broadcast( 0x59, null, p.Players.Length == 1 ? \"{0} has tied the duel due to time expiration.\" : \"{0} and {1} team have tied the duel due to time expiration.\", p.Players.Length == 1 ? \"You have tied the duel due to time expiration.\" : \"Your team has tied the duel due to time expiration.\" );\n\t\t\t\t\tfor ( int j = 0; j < p.Players.Length; ++j )\n\t\t\t\t\t{\n\t\t\t\t\t\tDuelPlayer pl = p.Players[j];\n\t\t\t\t\t\tif ( pl != null && !pl.Eliminated )\n\t\t\t\t\t\t\tDelayBounce( TimeSpan.FromSeconds( 8.0 ), pl.Mobile, null );\n\t\t\t\t\t}\n\t\t\t\t\tif ( p.TournyPart != null )\n\t\t\t\t\t\tremaining.Add( p.TournyPart );\n\t\t\t\t}\n\t\t\t\tfor ( int j = 0; j < p.Players.Length; ++j )\n\t\t\t\t{\n\t\t\t\t\tDuelPlayer pl = p.Players[j];\n\t\t\t\t\tif ( pl != null )\n\t\t\t\t\t{\n\t\t\t\t\t\tpl.Mobile.Delta( MobileDelta.Noto );\n\t\t\t\t\t\tpl.Mobile.SendEverything();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( m_Tournament != null )\n\t\t\t\tm_Tournament.HandleTie( m_Arena, m_Match, remaining );\n\t\t\tTimer.DelayCall( TimeSpan.FromSeconds( 10.0 ), new TimerCallback( Unregister ) );\n\t\t}\n\t\tpublic bool IsOneVsOne\n\t\t{\n\t\t\tget\n\t\t\t{\n\t\t\t\tif ( m_Participants.Count != 2 )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( ((Participant)m_Participants[0]).Players.Length != 1 )\n\t\t\t\t\treturn false;\n\t\t\t\tif ( ((Participant)m_Participants[1]).Players.Length != 1 )\n\t\t\t\t\treturn false;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tpublic static void Initialize()\n\t\t{\n\t\t\tEventSink.Speech += new SpeechEventHandler( EventSink_Speech );\n\t\t\tEventSink.Login += new LoginEventHandler( EventSink_Login );\n\t\t\tCommandSystem.Register( \"vli\", AccessLevel.GameMaster, new CommandEventHandler( vli_oc ) );\n\t\t}\n\t\tprivate static void vli_oc( CommandEventArgs e )\n\t\t{\n\t\t\te.Mobile.BeginTarget( -1, false, Targeting.TargetFlags.None, new TargetCallback( vli_ot ) );\n\t\t}\n\t\tprivate static void vli_ot( Mobile from, object obj )\n\t\t{\n\t\t\tif ( obj is PlayerMobile )\n\t\t\t{\n\t\t\t\tPlayerMobile pm = (PlayerMobile)obj;\n\t\t\t\tLadder ladder = Ladder.Instance;\n\t\t\t\tif ( ladder == null )\n\t\t\t\t\treturn;\n\t\t\t\tLadderEntry entry = ladder.Find( pm );\n\t\t\t\tif ( entry != null )\n\t\t\t\t\tfrom.SendGump( new PropertiesGump( from, entry ) );\n\t\t\t}\n\t\t}\n\t\tprivate static TimeSpan CombatDelay = TimeSpan.FromSeconds( 30.0 );\n\t\tprivate static TimeSpan AutoTieDelay = TimeSpan.FromMinutes( 15.0 );\n\t\tpublic static bool CheckCombat( Mobile m )\n\t\t{\n\t\t\tfor ( int i = 0; i < m.Aggressed.Count; ++i )\n\t\t\t{\n\t\t\t\tAggressorInfo info = m.Aggressed[i];\n\t\t\t\tif ( info.Defender.Player && (DateTime.UtcNow - info.LastCombatTime) < CombatDelay )\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\tfor ( int i = 0; i < m.Aggressors.Count; ++i )\n\t\t\t{\n\t\t\t\tAggressorInfo info = m.Aggressors[i];\n\t\t\t\tif ( info.Attacker.Player && (DateTime.UtcNow - info.LastCombatTime) < CombatDelay )\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tprivate static void EventSink_Login( LoginEventArgs e )\n\t\t{\n\t\t\tPlayerMobile pm = e.Mobile as PlayerMobile;\n\t\t\tif ( pm == null )\n\t\t\t\treturn;\n\t\t\tDuelContext dc = pm.DuelContext;\n\t\t\tif ( dc == null )\n\t\t\t\treturn;\n\t\t\tif ( dc.ReadyWait && pm.DuelPlayer.Ready && !dc.Started && !dc.StartedBeginCountdown && !dc.Finished )\n\t\t\t{\n\t\t\t\tif ( dc.m_Tournament == null )\n\t\t\t\t\tpm.SendGump( new ReadyGump( pm, dc, dc.m_ReadyCount ) );\n\t\t\t}\n\t\t\telse if ( dc.ReadyWait && !dc.StartedBeginCountdown && !dc.Started && !dc.Finished )\n\t\t\t{\n\t\t\t\tif ( dc.m_Tournament == null )\n\t\t\t\t\tpm.SendGump( new ReadyUpGump( pm, dc ) );\n\t\t\t}\n\t\t\telse if ( dc.Initiator == pm && !dc.ReadyWait && !dc.StartedBeginCountdown && !dc.Started && !dc.Finished )\n\t\t\t\tpm.SendGump( new DuelContextGump( pm, dc ) );\n\t\t}\n\t\tprivate static void ViewLadder_OnTarget( Mobile from, object obj, object state )\n\t\t{\n\t\t\tif ( obj is PlayerMobile )\n\t\t\t{\n\t\t\t\tPlayerMobile pm = (PlayerMobile)obj;\n\t\t\t\tLadder ladder = (Ladder)state;\n\t\t\t\tLadderEntry entry = ladder.Find( pm );\n\t\t\t\tif ( entry == null )\n\t\t\t\t\treturn; // sanity\n\t\t\t\tstring text = String.Format( \"{{0}} are ranked {0} at level {1}.\", LadderGump.Rank( entry.Index + 1 ), Ladder.GetLevel( entry.Experience ) );\n\t\t\t\tpm.PrivateOverheadMessage( MessageType.Regular, pm.SpeechHue, true, String.Format( text, from==pm?\"You\":\"They\" ), from.NetState );\n\t\t\t}\n\t\t\telse if ( obj is Mobile )\n\t\t\t{\n\t\t\t\tMobile mob = (Mobile)obj;\n\t\t\t\tif ( mob.Body.IsHuman )\n\t\t\t\t\tmob.PrivateOverheadMessage( MessageType.Regular, mob.SpeechHue, false, \"I'm not a duelist, and quite frankly, I resent the implication.\", from.NetState );\n\t\t\t\telse\n\t\t\t\t\tmob.PrivateOverheadMessage( MessageType.Regular, 0x3B2, true, \"It's probably better than you.\", from.NetState );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfrom.SendMessage( \"That's not a player.\" );\n\t\t\t}\n\t\t}\n\t\tprivate static void EventSink_Speech( SpeechEventArgs e )\n\t\t{\n\t\t\tif ( e.Handled )\n\t\t\t\treturn;\n\t\t\tPlayerMobile pm = e.Mobile as PlayerMobile;\n\t\t\tif ( pm == null )\n\t\t\t\treturn;\n\t\t\tif ( Insensitive.Contains( e.Speech, \"i wish to duel\" ) )\n\t\t\t{\n\t\t\t\tif ( !pm.CheckAlive() )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse if ( pm.Region.IsPartOf( typeof( Regions.Jail ) ) )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse if ( CheckCombat( pm ) )\n\t\t\t\t{\n\t\t\t\t\te.Mobile.SendMessage( 0x22, \"You have recently been in combat with another player and must wait before starting a duel.\" );\n\t\t\t\t}\n\t\t\t\telse if ( pm.DuelContext != null )\n\t\t\t\t{\n\t\t\t\t\tif ( pm.DuelContext.Initiator == pm )\n\t\t\t\t\t\te.Mobile.SendMessage( 0x22, \"You have already started a duel.\" );\n\t\t\t\t\telse\n\t\t\t\t\t\te.Mobile.SendMessage( 0x22, \"You have already been challenged in a duel.\" );\n\t\t\t\t}\n\t\t\t\telse if ( TournamentController.IsActive )\n\t\t\t\t{\n\t\t\t\t\te.Mobile.SendMessage( 0x22, \"You may not start a duel while a tournament is active.\" );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tpm.SendGump( new DuelContextGump( pm, new DuelContext( pm, RulesetLayout.Root ) ) );\n\t\t\t\t\te.Handled = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( Insensitive.Equals( e.Speech, \"change arena preferences\" ) )\n\t\t\t{\n\t\t\t\tif ( !pm.CheckAlive() )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tPreferences prefs = Preferences.Instance;\n\t\t\t\t\tif ( prefs != null )\n\t\t\t\t\t{\n\t\t\t\t\t\te.Mobile.CloseGump( typeof( PreferencesGump ) );\n\t\t\t\t\t\te.Mobile.SendGump( new PreferencesGump( e.Mobile, prefs ) );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( Insensitive.Equals( e.Speech, \"showladder\" ) )\n\t\t\t{\n\t\t\t\te.Blocked=true;\n\t\t\t\tif ( !pm.CheckAlive() )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tLadder instance = Ladder.Instance;\n\t\t\t\t\tif ( instance == null )\n\t\t\t\t\t{\n\t\t\t\t\t\t//pm.SendMessage( \"Ladder not yet initialized.\" );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tLadderEntry entry = instance.Find( pm );\n\t\t\t\t\t\tif ( entry == null )\n\t\t\t\t\t\t\treturn; // sanity\n\t\t\t\t\t\tstring text = String.Format( \"{{0}} {{1}} ranked {0} at level {1}.\", LadderGump.Rank( entry.Index + 1 ), Ladder.GetLevel( entry.Experience ) );\n\t\t\t\t\t\tpm.LocalOverheadMessage( MessageType.Regular, pm.SpeechHue, true, String.Format( text, \"You\", \"are\" ) );\n\t\t\t\t\t\tpm.NonlocalOverheadMessage( MessageType.Regular, pm.SpeechHue, true, String.Format( text, pm.Name, \"is\" ) );\n\t\t\t\t\t\t//pm.PublicOverheadMessage( MessageType.Regular, pm.SpeechHue, true, String.Format( \"Level {0} with {1} win{2} and {3} loss{4}.\", Ladder.GetLevel( entry.Experience ), entry.Wins, entry.Wins==1?\"\":\"s\", entry.Losses, entry.Losses==1?\"\":\"es\" ) );\n\t\t\t\t\t\t//pm.PublicOverheadMessage( MessageType.Regular, pm.SpeechHue, true, String.Format( \"Level {0} with {1} win{2} and {3} loss{4}.\", Ladder.GetLevel( entry.Experience ), entry.Wins, entry.Wins==1?\"\":\"s\", entry.Losses, entry.Losses==1?\"\":\"es\" ) );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( Insensitive.Equals( e.Speech, \"viewladder\" ) )\n\t\t\t{\n\t\t\t\te.Blocked=true;\n\t\t\t\tif ( !pm.CheckAlive() )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tLadder instance = Ladder.Instance;\n\t\t\t\t\tif ( instance == null )\n\t\t\t\t\t{\n\t\t\t\t\t\t//pm.SendMessage( \"Ladder not yet initialized.\" );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tpm.SendMessage( \"Target a player to view their ranking and level.\" );\n\t\t\t\t\t\tpm.BeginTarget( 16, false, Targeting.TargetFlags.None, new TargetStateCallback( ViewLadder_OnTarget ), instance );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( Insensitive.Contains( e.Speech, \"i yield\" ) )\n\t\t\t{\n\t\t\t\tif ( !pm.CheckAlive() )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse if ( pm.DuelContext == null )\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t\telse if ( pm.DuelContext.Finished )\n\t\t\t\t{\n\t\t\t\t\te.Mobile.SendMessage( 0x22, \"The duel is already finished.\" );\n\t\t\t\t}\n\t\t\t\telse if ( !pm.DuelContext.Started )\n\t\t\t\t{\n\t\t\t\t\tDuelContext dc = pm.DuelContext;\n\t\t\t\t\tMobile init = dc.Initiator;\n\t\t\t\t\tif ( pm.DuelContext.StartedBeginCountdown )\n\t\t\t\t\t{\n\t\t\t\t\t\te.Mobile.SendMessage( 0x22, \"The duel has not yet started.\" );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tDuelPlayer pl = pm.DuelContext.Find( pm );\n\t\t\t\t\t\tif ( pl == null )\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\tParticipant p = pl.Participant;\n\t\t\t\t\t\tif ( !pm.DuelContext.ReadyWait ) // still setting stuff up\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tp.Broadcast( 0x22, null, \"{0} has yielded.\", \"You have yielded.\" );\n\t\t\t\t\t\t\tif ( init == pm )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdc.Unregister();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tp.Nullify( pl );\n\t\t\t\t\t\t\t\tpm.DuelPlayer=null;\n\t\t\t\t\t\t\t\tNetState ns = init.NetState;\n\t\t\t\t\t\t\t\tif ( ns != null )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tforeach ( Gump g in ns.Gumps )\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tif ( g is ParticipantGump )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tParticipantGump pg = (ParticipantGump)g;\n\t\t\t\t\t\t\t\t\t\t\tif ( pg.Participant == p )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tinit.SendGump( new ParticipantGump( init, dc, p ) );\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse if ( g is DuelContextGump )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tDuelContextGump dcg = (DuelContextGump)g;\n\t\t\t\t\t\t\t\t\t\t\tif ( dcg.Context == dc )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tinit.SendGump( new DuelContextGump( init, dc ) );\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if ( !pm.DuelContext.StartedReadyCountdown ) // at ready stage\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tp.Broadcast( 0x22, null, \"{0} has yielded.\", \"You have yielded.\" );\n\t\t\t\t\t\t\tdc.m_Yielding=true;\n\t\t\t\t\t\t\tdc.RejectReady( pm, null );\n\t\t\t\t\t\t\tdc.m_Yielding=false;\n\t\t\t\t\t\t\tif ( init == pm )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdc.Unregister();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if ( dc.m_Registered )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tp.Nullify( pl );\n\t\t\t\t\t\t\t\tpm.DuelPlayer=null;\n\t\t\t\t\t\t\t\tNetState ns = init.NetState;\n\t\t\t\t\t\t\t\tif ( ns != null )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tbool send=true;\n\t\t\t\t\t\t\t\t\tforeach ( Gump g in ns.Gumps )\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tif ( g is ParticipantGump )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tParticipantGump pg = (ParticipantGump)g;\n\t\t\t\t\t\t\t\t\t\t\tif ( pg.Participant == p )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tinit.SendGump( new ParticipantGump( init, dc, p ) );\n\t\t\t\t\t\t\t\t\t\t\t\tsend=false;\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse if ( g is DuelContextGump )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tDuelContextGump dcg = (DuelContextGump)g;\n\t\t\t\t\t\t\t\t\t\t\tif ( dcg.Context == dc )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tinit.SendGump( new DuelContextGump( init, dc ) );\n\t\t\t\t\t\t\t\t\t\t\t\tsend=false;\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( send )\n\t\t\t\t\t\t\t\t\t\tinit.SendGump( new DuelContextGump( init, dc ) );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif ( pm.DuelContext.m_Countdown != null )\n\t\t\t\t\t\t\t\tpm.DuelContext.m_Countdown.Stop();\n\t\t\t\t\t\t\tpm.DuelContext.m_Countdown= null;\n\t\t\t\t\t\t\tpm.DuelContext.m_StartedReadyCountdown=false;\n\t\t\t\t\t\t\tp.Broadcast( 0x22, null, \"{0} has yielded.\", \"You have yielded.\" );\n\t\t\t\t\t\t\tdc.m_Yielding=true;\n\t\t\t\t\t\t\tdc.RejectReady( pm, null );\n\t\t\t\t\t\t\tdc.m_Yielding=false;\n\t\t\t\t\t\t\tif ( init == pm )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdc.Unregister();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if ( dc.m_Registered )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tp.Nullify( pl );\n\t\t\t\t\t\t\t\tpm.DuelPlayer=null;\n\t\t\t\t\t\t\t\tNetState ns = init.NetState;\n\t\t\t\t\t\t\t\tif ( ns != null )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tbool send=true;\n\t\t\t\t\t\t\t\t\tforeach ( Gump g in ns.Gumps )\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tif ( g is ParticipantGump )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tParticipantGump pg = (ParticipantGump)g;\n\t\t\t\t\t\t\t\t\t\t\tif ( pg.Participant == p )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tinit.SendGump( new ParticipantGump( init, dc, p ) );\n\t\t\t\t\t\t\t\t\t\t\t\tsend=false;\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse if ( g is DuelContextGump )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tDuelContextGump dcg = (DuelContextGump)g;\n\t\t\t\t\t\t\t\t\t\t\tif ( dcg.Context == dc )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tinit.SendGump( new DuelContextGump( init, dc ) );\n\t\t\t\t\t\t\t\t\t\t\t\tsend=false;\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( send )\n\t\t\t\t\t\t\t\t\t\tinit.SendGump( new DuelContextGump( init, dc ) );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tDuelPlayer pl = pm.DuelContext.Find( pm );\n\t\t\t\t\tif ( pl != null )\n\t\t\t\t\t{\n\t\t\t\t\t\tif ( pm.DuelContext.IsOneVsOne )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\te.Mobile.SendMessage( 0x22, \"You may not yield a 1 on 1 match.\" );\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if ( pl.Eliminated )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\te.Mobile.SendMessage( 0x22, \"You have already been eliminated.\" );\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpm.LocalOverheadMessage( MessageType.Regular, 0x22, false, \"You have yielded.\" );\n\t\t\t\t\t\t\tpm.NonlocalOverheadMessage( MessageType.Regular, 0x22, false, String.Format( \"{0} has yielded.\", pm.Name ) );\n\t\t\t\t\t\t\tpm.DuelContext.m_Yielding=true;\n\t\t\t\t\t\t\tpm.Kill();\n\t\t\t\t\t\t\tpm.DuelContext.m_Yielding=false;\n\t\t\t\t\t\t\tif ( pm.Alive ) // invul, ...\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tpl.Eliminated = true;\n\t\t\t\t\t\t\t\tpm.DuelContext.RemoveAggressions( pm );\n\t\t\t\t\t\t\t\tpm.DuelContext.SendOutside( pm );\n\t\t\t\t\t\t\t\tpm.DuelContext.Refresh( pm, null );\n\t\t\t\t\t\t\t\tDebuff( pm );\n\t\t\t\t\t\t\t\tCancelSpell( pm );\n\t\t\t\t\t\t\t\tpm.Frozen = false;\n\t\t\t\t\t\t\t\tParticipant winner = pm.DuelContext.CheckCompletion();\n\t\t\t\t\t\t\t\tif ( winner != null )\n\t\t\t\t\t\t\t\t\tpm.DuelContext.Finish( winner );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\te.Mobile.SendMessage( 0x22, \"BUG: Unable to find duel context.\" );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpublic DuelContext( Mobile initiator, RulesetLayout layout ) : this( initiator, layout, true )\n\t\t{\n\t\t}\n\t\tpublic DuelContext( Mobile initiator, RulesetLayout layout, bool addNew )\n\t\t{\n\t\t\tm_Initiator = initiator;\n\t\t\tm_Participants = new ArrayList();\n\t\t\tm_Ruleset = new Ruleset( layout );\n\t\t\tm_Ruleset.ApplyDefault( layout.Defaults[0] );\n\t\t\tif ( addNew )\n\t\t\t{\n\t\t\t\tm_Participants.Add( new Participant( this, 1 ) );\n\t\t\t\tm_Participants.Add( new Participant( this, 1 ) );\n\t\t\t\t((Participant)m_Participants[0]).Add( initiator );\n\t\t\t}\n\t\t}\n\t\tpublic void CloseAllGumps()\n\t\t{\n\t\t\tType[] types = new Type[]{ typeof( DuelContextGump ), typeof( ParticipantGump ), typeof( RulesetGump ) };\n\t\t\tint[] defs = new int[]{ -1, -1, -1 };\n\t\t\tfor ( int i = 0; i < m_Participants.Count; ++i )\n\t\t\t{\nNext line of code:<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n", "arg_1": {"max_gen_toks": 64, "temperature": 1.0, "do_sample": false, "until": []}}}, "resps": [["The code you've provided is part of a **ConPVP (Concurrent Player vs Player)** system in **Ragnarok Online** (or a similar game engine), and it's handling **duel mechanics**, including **rulesets**, **participants**, **countdowns**, **item and spell restrictions**, and"]], "filtered_resps": ["The code you've provided is part of a **ConPVP (Concurrent Player vs Player)** system in **Ragnarok Online** (or a similar game engine), and it's handling **duel mechanics**, including **rulesets**, **participants**, **countdowns**, **item and spell restrictions**, and"], "filter": "none", "metrics": ["score", "code_sim_score"], "doc_hash": "9f6b8a47dcc861df3fd051ce63f018a19cc65f238dac484829ea549cc234e124", "prompt_hash": "126e589b48121c7df7ce433b063b145131563d30d019df0cfaf44a39c59714f7", "target_hash": "5e341b3b88c89c5523752d615a397a151e1799a89a898e82255b6deb33edc8f5", "score": 0.18, "code_sim_score": 0.18}
{"doc_id": 1, "doc": {"question": "", "context": "Please complete the code given below. \nimport networkx as nx \nimport pickle\nfrom Queue import PriorityQueue \nimport copy\nimport random\nimport string\nimport sys\nclass MultiDiGraph_EdgeKey(nx.MultiDiGraph):\n \"\"\"\n MultiDiGraph which assigns unique keys to every edge.\n Adds a dictionary edge_index which maps edge keys to (u, v, data) tuples.\n This is not a complete implementation. For Edmonds algorithm, we only use\n add_node and add_edge, so that is all that is implemented here. During\n additions, any specified keys are ignored---this means that you also\n cannot update edge attributes through add_node and add_edge.\n \"\"\"\n def __init__(self, data=None, **attr):\n cls = super(MultiDiGraph_EdgeKey, self)\n cls.__init__(data=data, **attr)\n self._cls = cls\n self.edge_index = {}\n def remove_node(self, n):\n keys = set([])\n for keydict in self.pred[n].values():\n keys.update(keydict)\n for keydict in self.succ[n].values():\n keys.update(keydict)\n for key in keys:\n del self.edge_index[key]\n self._cls.remove_node(n)\n def remove_nodes_from(self, nbunch):\n for n in nbunch:\n self.remove_node(n)\n def add_edge(self, u, v, key, attr_dict=None, **attr):\n \"\"\"\n Key is now required.\n \"\"\"\n if key in self.edge_index:\n uu, vv, _ = self.edge_index[key]\n if (u != uu) or (v != vv):\n raise Exception(\"Key {0!r} is already in use.\".format(key))\n self._cls.add_edge(u, v, key=key, attr_dict=attr_dict, **attr)\n self.edge_index[key] = (u, v, self.succ[u][v][key])\n def add_edges_from(self, ebunch, attr_dict=None, **attr):\n for edge in ebunch:\n \tself.add_edge(*edge)\n def remove_edge_with_key(self, key):\n try:\n u, v, _ = self.edge_index[key]\n # print ('***',u,v,key)\n except KeyError:\n raise KeyError('Invalid edge key {0!r}'.format(key))\n else:\n del self.edge_index[key]\n # print ('***** self.edge_index',self.edge_index)\n self._cls.remove_edge(u, v, key)\n def remove_edges_from(self, ebunch):\n raise NotImplementedError\ndef random_string(L=15, seed=None):\n random.seed(seed)\n return ''.join([random.choice(string.ascii_letters) for n in range(L)])\nclass Camerini():\n\tdef __init__(self, graph, Y=nx.DiGraph(), Z=nx.DiGraph(), attr='weight'):\n\t\tself.original_graph = graph\n\t\tself.attr = attr\n\t\tself._init(Y=Y, Z=Z)\n\t\tself.template = random_string()\n\t\n\tdef _init(self, graph=None, Y=nx.DiGraph(), Z=nx.DiGraph()):\n\t\tself.graph = MultiDiGraph_EdgeKey()\n\t\tif graph is None:\n\t\t\tgraph = self.original_graph\n\t\tfor key, (u, v, data) in enumerate(graph.edges(data=True)):\n\t\t\tif (u,v) not in Z.edges():\n\t\t\t\tself.graph.add_edge(u,v,key,data.copy())\n\t\t\t\n\t\tfor Y_edge in Y.edges(data=True):\n\t\t\tfor (u,v) in self.graph.in_edges([Y_edge[1]]):\n\t\t\t\tif u != Y_edge[0]:\n\t\t\t\t\tself.graph.remove_edge(u,v)\n\tdef best_incoming_edge(self, node, graph):\n\t\tmax_weight = float('-inf')\n\t\te = None\n\t\t# print ('Graph',graph.edges())\n\t\tfor u,v,key,data in graph.in_edges([node], data=True, keys=True):\n\t\t\t# print ('edge',u,v,data)\n\t\t\tif max_weight <= data[self.attr]:\n\t\t\t\tmax_weight = data[self.attr]\n\t\t\t\te = (u,v,key,data)\n\t\treturn e\n\tdef collapse_cycle(self, graph, cycle, B, new_node):\t\t\t\n\t\tfor node in cycle:\n\t\t\tfor u,v,key,data in graph.out_edges([node], data=True, keys=True):\n\t\t\t\tgraph.remove_edge_with_key(key)\n\t\t\t\tif v not in cycle:\n\t\t\t\t\tdd = data.copy()\n\t\t\t\t\tgraph.add_edge(new_node,v,key,**dd)\t\t\n\t\t\tfor u,v,key,data in graph.in_edges([node], data=True, keys=True):\n\t\t\t\tif u in cycle:\n\t\t\t\t\t# it will be delete later\n\t\t\t\t\tcontinue\n\t\t\t\tgraph.remove_edge_with_key(key)\n\t\t\t\tdd = data.copy()\n\t\t\t\tdd_eh = list(B.in_edges([node], data=True))[0][2] \n\t\t\t\tdd[self.attr] = dd[self.attr] - dd_eh[self.attr]\n\t\t\t\tgraph.add_edge(u, new_node, key, **dd)\n\t\tfor node in cycle:\n\t\t\tB.remove_node(node)\n\t\treturn graph, B\n\tdef add_b_to_branching(self, exposed_nodes, order, M, supernodes, B):\n\t\tv = exposed_nodes.pop(0)\n\t\torder.append(v)\n\t\tb = self.best_incoming_edge(v, M)\n\t\tif b is None:\n\t\t\tif v in supernodes:\n\t\t\t\tsupernodes.remove(v)\n\t\t\treturn exposed_nodes, order, M, supernodes, B, None\n\t\tb_u, b_v, b_key, b_data = b\n\t\tdata = {self.attr: b_data[self.attr], 'origin': b_data['origin']}\n\t\tB.add_edge(b_u, b_v, **data)\n\t\treturn exposed_nodes, order, M, supernodes, B, b\n\tdef contracting_phase(self, B, n, supernodes, exposed_nodes, M, C, root):\n\t\tcycles = list(nx.simple_cycles(B))\n\t\tif len(cycles) > 0:\n\t\t\tu = 'v_'+str(n)\n\t\t\tsupernodes.append(str(u))\n\t\t\texposed_nodes.append(u)\n\t\t\tfor node in cycles[0]:\n\t\t\t\tC[str(node)] = str(u)\n\t\t\tM, B = self.collapse_cycle(M, cycles[0], B, u)\n\t\t\tfor node in B.nodes():\n\t\t\t\tif B.in_edges([node]) == []:\n\t\t\t\t\tif B.out_edges([node]) == []:\n\t\t\t\t\t\tB.remove_node(node)\n\t\t\t\t\tif node != root and node not in exposed_nodes:\n\t\t\t\t\t\texposed_nodes.append(node)\n\t\t\tn += 1\n\t\treturn B, n, supernodes, exposed_nodes, M, C\n\tdef best(self, root):\n\t\tM = self.graph\n\t\tfor u,v,key,data in M.edges(data=True, keys=True):\n\t\t\tdata['origin'] = (u,v,key,{self.attr: data[self.attr]})\n\t\tn = 0\n\t\tB = nx.DiGraph()\n\t\t# C contains for every node its parent node, so it will be easy to find the path in the collapsing phase\n\t\t# from an isolated root v_1 to v_k\n\t\tnodes = M.nodes()\n\t\tif len(nodes) == 1:\n\t\t\tA = nx.DiGraph()\n\t\t\tA.add_node(nodes[0])\n\t\tC = {str(node): None for node in nodes} \n\t\tdel C[str(root)]\n\t\texposed_nodes = [node for node in nodes]\n\t\texposed_nodes.remove(root)\n\t\tsupernodes = []\n\t\tbeta = {}\n\t\torder = []\n\t\t# collapsing phase\n\t\twhile len(exposed_nodes) > 0:\n\t\t\texposed_nodes, order, M, supernodes, B, b = self.add_b_to_branching(exposed_nodes, order, M, supernodes, B)\n\t\t\tif b is None:\n\t\t\t\tcontinue\n\t\t\tb_u, b_v, b_key, b_data = b\n\t\t\tbeta[b_v] = (b_u, b_v, b_key, b_data)\n\t\t\tB, n, supernodes, exposed_nodes, M, C = self.contracting_phase(B, n, supernodes, exposed_nodes, M, C, root)\n\t\t# expanding phase\n\t\twhile len(supernodes) > 0:\n\t\t\tv_1 = supernodes.pop()\n\t\t\torigin_edge_v_1 = beta[v_1][3]['origin'] \n\t\t\tv_k = origin_edge_v_1[1]\n\t\t\tbeta[v_k] = beta[v_1]\n\t\t\tv_i = str(C[str(v_k)])\n\t\t\twhile v_i != v_1:\n\t\t\t\tsupernodes.remove(v_i)\n\t\t\t\tv_i = C.pop(v_i)\n\t\tA = nx.DiGraph()\n\t\tfor k, edge in beta.items():\n\t\t\tif k in nodes:\n\t\t\t\tu,v,key,data = edge[3]['origin']\n\t\t\t\tA.add_edge(u,v,**data.copy())\n\t\treturn A\n\tdef get_priority_queue_for_incoming_node(self, graph, v, b):\n\t\tQ = PriorityQueue()\n\t\tfor u,v,key,data in graph.in_edges([v], data=True, keys=True):\n\t\t\tif key == b[2]:\n\t\t\t\tcontinue\n\t\t\tQ.put((-data[self.attr], (u,v,key,data)))\n\t\treturn Q\n\tdef seek(self, b, A, graph):\n\t\tv = b[1]\n\t\tQ = self.get_priority_queue_for_incoming_node(graph, v, b)\n\t\twhile not Q.empty():\n\t\t\tf = Q.get()\n\t\t\ttry:\n\t\t\t\t# v = T(b) is an ancestor of O(f)=f[1][1]?\n\t\t\t\tv_origin = b[3]['origin'][1]\n\t\t\t\tf_origin = f[1][3]['origin'][0] \n\t\t\t\tnx.shortest_path(A, v_origin, f_origin)\n\t\t\texcept nx.exception.NetworkXNoPath:\n\t\t\t\treturn f[1]\n\t\treturn None\n\tdef next(self, A, Y, Z, graph=None, root='R'):\n\t\td = float('inf')\n\t\tedge = None\n\t\tif graph is not None:\n\t\t\tself._init(graph)\n\t\tM = self.graph\n\t\tfor u,v,key,data in M.edges(data=True, keys=True):\n\t\t\tdata['origin'] = (u,v,key,{self.attr: data[self.attr]})\n\t\tn = 0\n\t\tB = nx.DiGraph()\n\t\tnodes = M.nodes()\n\t\tC = {str(node): None for node in nodes} \n\t\texposed_nodes = [node for node in nodes]\n\t\tif 'R' in exposed_nodes: \n\t\t\texposed_nodes.remove('R')\n\t\torder = []\n\t\tsupernodes = []\n\t\twhile len(exposed_nodes) > 0:\n\t\t\texposed_nodes, order, M, supernodes, B, b = self.add_b_to_branching(exposed_nodes, order, M, supernodes, B)\n\t\t\tif b is None:\n\t\t\t\tcontinue\n\t\t\tb_u, b_v, b_key, b_data = b\n\t\t\torigin_u, origin_v = b_data['origin'][:2]\n\t\t\tif (origin_u, origin_v) in A.edges():\n\t\t\t\tif (origin_u, origin_v) not in Y.edges():\n\t\t\t\t\tf = self.seek(b, A, M)\n\t\t\t\t\tif f is not None:\n\t\t\t\t\t\tf_u, f_v, f_key, f_data = f\n\t\t\t\t\t\tif b_data[self.attr] - f_data[self.attr] < d:\n\t\t\t\t\t\t\tedge = b\n\t\t\t\t\t\t\td = b_data[self.attr] - f_data[self.attr]\n\t\t\tB, n, supernodes, exposed_nodes, M, C = self.contracting_phase(B, n, supernodes, exposed_nodes, M, C, root)\n\t\treturn edge[3]['origin'], d\n\tdef ranking(self, k, graph=None, Y=nx.DiGraph(), Z=nx.DiGraph(), mode='branching', root='R'):\n\t\tif graph is not None:\n\t\t\tself._init(graph, Y, Z)\n\t\tif root == 'R' and mode == 'branching':\n\t\t\tbest = self.best_branching\n\t\telif root == 'R' and mode == 'arborescence_no_rooted':\n\t\t\tbest = self.best_arborescence_no_rooted\n\t\telse:\n\t\t\tbest = self.best_arborescence_rooted\n\t\t\n\t\tgraph = self.graph.copy()\n\t\tA = best(root) \n\t\troots = self.find_roots(A)\n\t\tif 'R' in roots:\n\t\t\troots.remove('R')\n\t\tprint ('roots for ranking',roots)\n\t\tself._init(graph)\n\t\te, d = self.next(A, Y, Z) \n\t\tP = PriorityQueue()\n\t\tw = self.get_graph_score(A) - d if d != float('inf') else float('inf') \n\t\tP.put( (-w, e, A, Y, Z) )\n\t\tsolutions = [A]\n\t\tfor j in range(1,k+1):\n\t\t\tw, e, A, Y, Z = P.get()\n\t\t\tw = -w \t\t\t\n\t\t\troots.extend([root for root in self.find_roots(A) if root not in roots])\n\t\t\tif 'R' in roots:\n\t\t\t\troots.remove('R')\n\t\t\tif w == float('-inf'):\n\t\t\t\treturn solutions\n\t\t\te_u, e_v, e_key, data = e\n\t\t\t\n\t\t\tY_ = Y.copy()\n\t\t\tY_.add_edge(e_u, e_v, **data.copy())\n\t\t\t\n\t\t\tZ_ = Z.copy()\n", "answers": ["\t\t\tZ_.add_edge(e_u, e_v, **data.copy())"], "length": 1069, "dataset": "lcc", "language": "python", "all_classes": null, "_id": "ca807f49d7c6f84dcae3df694bde685aa7f75a02e9d4f574", "answer_prefix": "Next line of code:\n", "task": "lcc", "max_new_tokens": 84}, "target": "['\\t\\t\\tZ_.add_edge(e_u, e_v, **data.copy())']", "arguments": {"gen_args_0": {"arg_0": "<|im_start|>user\nPlease complete the code given below. \nPlease complete the code given below. \nimport networkx as nx \nimport pickle\nfrom Queue import PriorityQueue \nimport copy\nimport random\nimport string\nimport sys\nclass MultiDiGraph_EdgeKey(nx.MultiDiGraph):\n \"\"\"\n MultiDiGraph which assigns unique keys to every edge.\n Adds a dictionary edge_index which maps edge keys to (u, v, data) tuples.\n This is not a complete implementation. For Edmonds algorithm, we only use\n add_node and add_edge, so that is all that is implemented here. During\n additions, any specified keys are ignored---this means that you also\n cannot update edge attributes through add_node and add_edge.\n \"\"\"\n def __init__(self, data=None, **attr):\n cls = super(MultiDiGraph_EdgeKey, self)\n cls.__init__(data=data, **attr)\n self._cls = cls\n self.edge_index = {}\n def remove_node(self, n):\n keys = set([])\n for keydict in self.pred[n].values():\n keys.update(keydict)\n for keydict in self.succ[n].values():\n keys.update(keydict)\n for key in keys:\n del self.edge_index[key]\n self._cls.remove_node(n)\n def remove_nodes_from(self, nbunch):\n for n in nbunch:\n self.remove_node(n)\n def add_edge(self, u, v, key, attr_dict=None, **attr):\n \"\"\"\n Key is now required.\n \"\"\"\n if key in self.edge_index:\n uu, vv, _ = self.edge_index[key]\n if (u != uu) or (v != vv):\n raise Exception(\"Key {0!r} is already in use.\".format(key))\n self._cls.add_edge(u, v, key=key, attr_dict=attr_dict, **attr)\n self.edge_index[key] = (u, v, self.succ[u][v][key])\n def add_edges_from(self, ebunch, attr_dict=None, **attr):\n for edge in ebunch:\n \tself.add_edge(*edge)\n def remove_edge_with_key(self, key):\n try:\n u, v, _ = self.edge_index[key]\n # print ('***',u,v,key)\n except KeyError:\n raise KeyError('Invalid edge key {0!r}'.format(key))\n else:\n del self.edge_index[key]\n # print ('***** self.edge_index',self.edge_index)\n self._cls.remove_edge(u, v, key)\n def remove_edges_from(self, ebunch):\n raise NotImplementedError\ndef random_string(L=15, seed=None):\n random.seed(seed)\n return ''.join([random.choice(string.ascii_letters) for n in range(L)])\nclass Camerini():\n\tdef __init__(self, graph, Y=nx.DiGraph(), Z=nx.DiGraph(), attr='weight'):\n\t\tself.original_graph = graph\n\t\tself.attr = attr\n\t\tself._init(Y=Y, Z=Z)\n\t\tself.template = random_string()\n\t\n\tdef _init(self, graph=None, Y=nx.DiGraph(), Z=nx.DiGraph()):\n\t\tself.graph = MultiDiGraph_EdgeKey()\n\t\tif graph is None:\n\t\t\tgraph = self.original_graph\n\t\tfor key, (u, v, data) in enumerate(graph.edges(data=True)):\n\t\t\tif (u,v) not in Z.edges():\n\t\t\t\tself.graph.add_edge(u,v,key,data.copy())\n\t\t\t\n\t\tfor Y_edge in Y.edges(data=True):\n\t\t\tfor (u,v) in self.graph.in_edges([Y_edge[1]]):\n\t\t\t\tif u != Y_edge[0]:\n\t\t\t\t\tself.graph.remove_edge(u,v)\n\tdef best_incoming_edge(self, node, graph):\n\t\tmax_weight = float('-inf')\n\t\te = None\n\t\t# print ('Graph',graph.edges())\n\t\tfor u,v,key,data in graph.in_edges([node], data=True, keys=True):\n\t\t\t# print ('edge',u,v,data)\n\t\t\tif max_weight <= data[self.attr]:\n\t\t\t\tmax_weight = data[self.attr]\n\t\t\t\te = (u,v,key,data)\n\t\treturn e\n\tdef collapse_cycle(self, graph, cycle, B, new_node):\t\t\t\n\t\tfor node in cycle:\n\t\t\tfor u,v,key,data in graph.out_edges([node], data=True, keys=True):\n\t\t\t\tgraph.remove_edge_with_key(key)\n\t\t\t\tif v not in cycle:\n\t\t\t\t\tdd = data.copy()\n\t\t\t\t\tgraph.add_edge(new_node,v,key,**dd)\t\t\n\t\t\tfor u,v,key,data in graph.in_edges([node], data=True, keys=True):\n\t\t\t\tif u in cycle:\n\t\t\t\t\t# it will be delete later\n\t\t\t\t\tcontinue\n\t\t\t\tgraph.remove_edge_with_key(key)\n\t\t\t\tdd = data.copy()\n\t\t\t\tdd_eh = list(B.in_edges([node], data=True))[0][2] \n\t\t\t\tdd[self.attr] = dd[self.attr] - dd_eh[self.attr]\n\t\t\t\tgraph.add_edge(u, new_node, key, **dd)\n\t\tfor node in cycle:\n\t\t\tB.remove_node(node)\n\t\treturn graph, B\n\tdef add_b_to_branching(self, exposed_nodes, order, M, supernodes, B):\n\t\tv = exposed_nodes.pop(0)\n\t\torder.append(v)\n\t\tb = self.best_incoming_edge(v, M)\n\t\tif b is None:\n\t\t\tif v in supernodes:\n\t\t\t\tsupernodes.remove(v)\n\t\t\treturn exposed_nodes, order, M, supernodes, B, None\n\t\tb_u, b_v, b_key, b_data = b\n\t\tdata = {self.attr: b_data[self.attr], 'origin': b_data['origin']}\n\t\tB.add_edge(b_u, b_v, **data)\n\t\treturn exposed_nodes, order, M, supernodes, B, b\n\tdef contracting_phase(self, B, n, supernodes, exposed_nodes, M, C, root):\n\t\tcycles = list(nx.simple_cycles(B))\n\t\tif len(cycles) > 0:\n\t\t\tu = 'v_'+str(n)\n\t\t\tsupernodes.append(str(u))\n\t\t\texposed_nodes.append(u)\n\t\t\tfor node in cycles[0]:\n\t\t\t\tC[str(node)] = str(u)\n\t\t\tM, B = self.collapse_cycle(M, cycles[0], B, u)\n\t\t\tfor node in B.nodes():\n\t\t\t\tif B.in_edges([node]) == []:\n\t\t\t\t\tif B.out_edges([node]) == []:\n\t\t\t\t\t\tB.remove_node(node)\n\t\t\t\t\tif node != root and node not in exposed_nodes:\n\t\t\t\t\t\texposed_nodes.append(node)\n\t\t\tn += 1\n\t\treturn B, n, supernodes, exposed_nodes, M, C\n\tdef best(self, root):\n\t\tM = self.graph\n\t\tfor u,v,key,data in M.edges(data=True, keys=True):\n\t\t\tdata['origin'] = (u,v,key,{self.attr: data[self.attr]})\n\t\tn = 0\n\t\tB = nx.DiGraph()\n\t\t# C contains for every node its parent node, so it will be easy to find the path in the collapsing phase\n\t\t# from an isolated root v_1 to v_k\n\t\tnodes = M.nodes()\n\t\tif len(nodes) == 1:\n\t\t\tA = nx.DiGraph()\n\t\t\tA.add_node(nodes[0])\n\t\tC = {str(node): None for node in nodes} \n\t\tdel C[str(root)]\n\t\texposed_nodes = [node for node in nodes]\n\t\texposed_nodes.remove(root)\n\t\tsupernodes = []\n\t\tbeta = {}\n\t\torder = []\n\t\t# collapsing phase\n\t\twhile len(exposed_nodes) > 0:\n\t\t\texposed_nodes, order, M, supernodes, B, b = self.add_b_to_branching(exposed_nodes, order, M, supernodes, B)\n\t\t\tif b is None:\n\t\t\t\tcontinue\n\t\t\tb_u, b_v, b_key, b_data = b\n\t\t\tbeta[b_v] = (b_u, b_v, b_key, b_data)\n\t\t\tB, n, supernodes, exposed_nodes, M, C = self.contracting_phase(B, n, supernodes, exposed_nodes, M, C, root)\n\t\t# expanding phase\n\t\twhile len(supernodes) > 0:\n\t\t\tv_1 = supernodes.pop()\n\t\t\torigin_edge_v_1 = beta[v_1][3]['origin'] \n\t\t\tv_k = origin_edge_v_1[1]\n\t\t\tbeta[v_k] = beta[v_1]\n\t\t\tv_i = str(C[str(v_k)])\n\t\t\twhile v_i != v_1:\n\t\t\t\tsupernodes.remove(v_i)\n\t\t\t\tv_i = C.pop(v_i)\n\t\tA = nx.DiGraph()\n\t\tfor k, edge in beta.items():\n\t\t\tif k in nodes:\n\t\t\t\tu,v,key,data = edge[3]['origin']\n\t\t\t\tA.add_edge(u,v,**data.copy())\n\t\treturn A\n\tdef get_priority_queue_for_incoming_node(self, graph, v, b):\n\t\tQ = PriorityQueue()\n\t\tfor u,v,key,data in graph.in_edges([v], data=True, keys=True):\n\t\t\tif key == b[2]:\n\t\t\t\tcontinue\n\t\t\tQ.put((-data[self.attr], (u,v,key,data)))\n\t\treturn Q\n\tdef seek(self, b, A, graph):\n\t\tv = b[1]\n\t\tQ = self.get_priority_queue_for_incoming_node(graph, v, b)\n\t\twhile not Q.empty():\n\t\t\tf = Q.get()\n\t\t\ttry:\n\t\t\t\t# v = T(b) is an ancestor of O(f)=f[1][1]?\n\t\t\t\tv_origin = b[3]['origin'][1]\n\t\t\t\tf_origin = f[1][3]['origin'][0] \n\t\t\t\tnx.shortest_path(A, v_origin, f_origin)\n\t\t\texcept nx.exception.NetworkXNoPath:\n\t\t\t\treturn f[1]\n\t\treturn None\n\tdef next(self, A, Y, Z, graph=None, root='R'):\n\t\td = float('inf')\n\t\tedge = None\n\t\tif graph is not None:\n\t\t\tself._init(graph)\n\t\tM = self.graph\n\t\tfor u,v,key,data in M.edges(data=True, keys=True):\n\t\t\tdata['origin'] = (u,v,key,{self.attr: data[self.attr]})\n\t\tn = 0\n\t\tB = nx.DiGraph()\n\t\tnodes = M.nodes()\n\t\tC = {str(node): None for node in nodes} \n\t\texposed_nodes = [node for node in nodes]\n\t\tif 'R' in exposed_nodes: \n\t\t\texposed_nodes.remove('R')\n\t\torder = []\n\t\tsupernodes = []\n\t\twhile len(exposed_nodes) > 0:\n\t\t\texposed_nodes, order, M, supernodes, B, b = self.add_b_to_branching(exposed_nodes, order, M, supernodes, B)\n\t\t\tif b is None:\n\t\t\t\tcontinue\n\t\t\tb_u, b_v, b_key, b_data = b\n\t\t\torigin_u, origin_v = b_data['origin'][:2]\n\t\t\tif (origin_u, origin_v) in A.edges():\n\t\t\t\tif (origin_u, origin_v) not in Y.edges():\n\t\t\t\t\tf = self.seek(b, A, M)\n\t\t\t\t\tif f is not None:\n\t\t\t\t\t\tf_u, f_v, f_key, f_data = f\n\t\t\t\t\t\tif b_data[self.attr] - f_data[self.attr] < d:\n\t\t\t\t\t\t\tedge = b\n\t\t\t\t\t\t\td = b_data[self.attr] - f_data[self.attr]\n\t\t\tB, n, supernodes, exposed_nodes, M, C = self.contracting_phase(B, n, supernodes, exposed_nodes, M, C, root)\n\t\treturn edge[3]['origin'], d\n\tdef ranking(self, k, graph=None, Y=nx.DiGraph(), Z=nx.DiGraph(), mode='branching', root='R'):\n\t\tif graph is not None:\n\t\t\tself._init(graph, Y, Z)\n\t\tif root == 'R' and mode == 'branching':\n\t\t\tbest = self.best_branching\n\t\telif root == 'R' and mode == 'arborescence_no_rooted':\n\t\t\tbest = self.best_arborescence_no_rooted\n\t\telse:\n\t\t\tbest = self.best_arborescence_rooted\n\t\t\n\t\tgraph = self.graph.copy()\n\t\tA = best(root) \n\t\troots = self.find_roots(A)\n\t\tif 'R' in roots:\n\t\t\troots.remove('R')\n\t\tprint ('roots for ranking',roots)\n\t\tself._init(graph)\n\t\te, d = self.next(A, Y, Z) \n\t\tP = PriorityQueue()\n\t\tw = self.get_graph_score(A) - d if d != float('inf') else float('inf') \n\t\tP.put( (-w, e, A, Y, Z) )\n\t\tsolutions = [A]\n\t\tfor j in range(1,k+1):\n\t\t\tw, e, A, Y, Z = P.get()\n\t\t\tw = -w \t\t\t\n\t\t\troots.extend([root for root in self.find_roots(A) if root not in roots])\n\t\t\tif 'R' in roots:\n\t\t\t\troots.remove('R')\n\t\t\tif w == float('-inf'):\n\t\t\t\treturn solutions\n\t\t\te_u, e_v, e_key, data = e\n\t\t\t\n\t\t\tY_ = Y.copy()\n\t\t\tY_.add_edge(e_u, e_v, **data.copy())\n\t\t\t\n\t\t\tZ_ = Z.copy()\nNext line of code:<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n", "arg_1": {"max_gen_toks": 64, "temperature": 1.0, "do_sample": false, "until": []}}}, "resps": [["The code you've provided is an implementation of **Camerini's algorithm** for finding a **minimum spanning arborescence** in a directed graph. It's a complex algorithm that involves several steps, including:\n\n- **Constructing a branching** (a directed tree with one root node).\n- **Collaps"]], "filtered_resps": ["The code you've provided is an implementation of **Camerini's algorithm** for finding a **minimum spanning arborescence** in a directed graph. It's a complex algorithm that involves several steps, including:\n\n- **Constructing a branching** (a directed tree with one root node).\n- **Collaps"], "filter": "none", "metrics": ["score", "code_sim_score"], "doc_hash": "6342302cf3ef3a9936ab03ed7d8558598544eb4e4de90e4a7ed5a3060a7f798d", "prompt_hash": "09cf708d03512cbe2031e73d175574c50f7a474feb19059286967ee00151e96d", "target_hash": "00767c228866c3b1427622fdce463ed59201cb438c040cc49a4f046c8569fcb4", "score": 0.12, "code_sim_score": 0.12}
{"doc_id": 2, "doc": {"question": "", "context": "Please complete the code given below. \n#! /usr/bin/env python\n# Last Change: Sun Dec 14 07:00 PM 2008 J\n\"\"\"Test for the sndfile class.\"\"\"\nfrom os.path import join, dirname\nimport os\nimport sys\nfrom numpy.testing import TestCase, assert_array_equal, dec\nimport numpy as np\nfrom audiolab import Sndfile, Format, available_encodings, available_file_formats\nfrom testcommon import open_tmp_file, close_tmp_file, TEST_DATA_DIR\n_DTYPE_TO_ENC = {np.float64 : 'float64', np.float32: 'float32', \n np.int32: 'pcm32', np.int16: 'pcm16'}\n# XXX: there is a lot to refactor here\nclass TestSndfile(TestCase):\n def test_basic_io(self):\n \"\"\" Check open, close and basic read/write\"\"\"\n # dirty !\n ofilename = join(TEST_DATA_DIR, 'test.wav')\n rfd, fd, cfilename = open_tmp_file('pysndfiletest.wav')\n try:\n nbuff = 22050\n # Open the test file for reading\n a = Sndfile(ofilename, 'r')\n nframes = a.nframes\n # Open the copy file for writing\n format = Format('wav', 'pcm16')\n b = Sndfile(fd, 'w', format, a.channels, a.samplerate)\n # Copy the data\n for i in range(nframes / nbuff):\n tmpa = a.read_frames(nbuff)\n assert tmpa.dtype == np.float\n b.write_frames(tmpa)\n nrem = nframes % nbuff\n tmpa = a.read_frames(nrem)\n assert tmpa.dtype == np.float\n b.write_frames(tmpa)\n a.close()\n b.close()\n finally:\n close_tmp_file(rfd, cfilename)\n @dec.skipif(sys.platform=='win32', \n \"Not testing opening by fd because does not work on win32\")\n def test_basic_io_fd(self):\n \"\"\" Check open from fd works\"\"\"\n ofilename = join(TEST_DATA_DIR, 'test.wav')\n fd = os.open(ofilename, os.O_RDONLY)\n hdl = Sndfile(fd, 'r')\n hdl.close()\n def test_raw(self):\n rawname = join(TEST_DATA_DIR, 'test.raw')\n format = Format('raw', 'pcm16', 'little')\n a = Sndfile(rawname, 'r', format, 1, 11025)\n assert a.nframes == 11290\n a.close()\n def test_float64(self):\n \"\"\"Check float64 write/read works\"\"\"\n self._test_read_write(np.float64)\n def test_float32(self):\n \"\"\"Check float32 write/read works\"\"\"\n self._test_read_write(np.float32)\n def test_int32(self):\n \"\"\"Check 32 bits pcm write/read works\"\"\"\n self._test_read_write(np.int32)\n def test_int16(self):\n \"\"\"Check 16 bits pcm write/read works\"\"\"\n self._test_read_write(np.int16)\n def _test_read_write(self, dtype):\n # dirty !\n ofilename = join(TEST_DATA_DIR, 'test.wav')\n rfd, fd, cfilename = open_tmp_file('pysndfiletest.wav')\n try:\n nbuff = 22050\n # Open the test file for reading\n a = Sndfile(ofilename, 'r')\n nframes = a.nframes\n # Open the copy file for writing\n format = Format('wav', _DTYPE_TO_ENC[dtype])\n b = Sndfile(fd, 'w', format, a.channels, a.samplerate)\n # Copy the data in the wav file\n for i in range(nframes / nbuff):\n tmpa = a.read_frames(nbuff, dtype=dtype)\n assert tmpa.dtype == dtype\n b.write_frames(tmpa)\n nrem = nframes % nbuff\n tmpa = a.read_frames(nrem)\n b.write_frames(tmpa)\n a.close()\n b.close()\n # Now, reopen both files in for reading, and check data are\n # the same\n a = Sndfile(ofilename, 'r')\n b = Sndfile(cfilename, 'r')\n for i in range(nframes / nbuff):\n tmpa = a.read_frames(nbuff, dtype=dtype)\n tmpb = b.read_frames(nbuff, dtype=dtype)\n assert_array_equal(tmpa, tmpb)\n a.close()\n b.close()\n finally:\n close_tmp_file(rfd, cfilename)\n #def test_supported_features(self):\n # for i in available_file_formats():\n # print \"Available encodings for format %s are : \" % i\n # for j in available_encodings(i):\n # print '\\t%s' % j\n def test_short_io(self):\n self._test_int_io(np.short)\n def test_int32_io(self):\n self._test_int_io(np.int32)\n def _test_int_io(self, dt):\n # TODO: check if neg or pos value is the highest in abs\n rfd, fd, cfilename = open_tmp_file('pysndfiletest.wav')\n try:\n # Use almost full possible range possible for the given data-type\n nb = 2 ** (8 * np.dtype(dt).itemsize - 3)\n fs = 22050\n nbuff = fs\n a = np.random.random_integers(-nb, nb, nbuff)\n a = a.astype(dt)\n # Open the file for writing\n format = Format('wav', _DTYPE_TO_ENC[dt])\n b = Sndfile(fd, 'w', format, 1, fs)\n b.write_frames(a)\n b.close()\n b = Sndfile(cfilename, 'r')\n read_a = b.read_frames(nbuff, dtype=dt)\n b.close()\n assert_array_equal(a, read_a)\n finally:\n close_tmp_file(rfd, cfilename)\n def test_mismatch(self):\n \"\"\"Check for bad arguments.\"\"\"\n # This test open a file for writing, but with bad args (channels and\n # nframes inverted)\n rfd, fd, cfilename = open_tmp_file('pysndfiletest.wav')\n try:\n # Open the file for writing\n format = Format('wav', 'pcm16')\n try:\n b = Sndfile(fd, 'w', format, channels=22000, samplerate=1)\n raise AssertionError(\"Try to open a file with more than 256 \"\\\n \"channels, this should not succeed !\")\n except ValueError, e:\n pass\n finally:\n close_tmp_file(rfd, cfilename)\n def test_bigframes(self):\n \"\"\" Try to seek really far.\"\"\"\n rawname = join(TEST_DATA_DIR, 'test.wav')\n a = Sndfile(rawname, 'r')\n try:\n try:\n a.seek(2 ** 60)\n raise Exception, \\\n \"Seek really succeded ! This should not happen\"\n except IOError, e:\n pass\n finally:\n a.close()\n def test_float_frames(self):\n \"\"\" Check nframes can be a float\"\"\"\n rfd, fd, cfilename = open_tmp_file('pysndfiletest.wav')\n try:\n # Open the file for writing\n format = Format('wav', 'pcm16')\n a = Sndfile(fd, 'rw', format, channels=1, samplerate=22050)\n tmp = np.random.random_integers(-100, 100, 1000)\n tmp = tmp.astype(np.short)\n a.write_frames(tmp)\n a.seek(0)\n a.sync()\n ctmp = a.read_frames(1e2, dtype=np.short)\n a.close()\n finally:\n close_tmp_file(rfd, cfilename)\n def test_nofile(self):\n \"\"\" Check the failure when opening a non existing file.\"\"\"\n try:\n f = Sndfile(\"floupi.wav\", \"r\")\n raise AssertionError(\"call to non existing file should not succeed\")\n except IOError:\n pass\n except Exception, e:\n raise AssertionError(\"opening non existing file should raise\" \\\n \" a IOError exception, got %s instead\" %\n e.__class__)\nclass TestSeek(TestCase):\n def test_simple(self):\n ofilename = join(TEST_DATA_DIR, 'test.wav')\n # Open the test file for reading\n a = Sndfile(ofilename, 'r')\n nframes = a.nframes\n buffsize = 1024\n buffsize = min(nframes, buffsize)\n # First, read some frames, go back, and compare buffers\n buff = a.read_frames(buffsize)\n a.seek(0)\n buff2 = a.read_frames(buffsize)\n assert_array_equal(buff, buff2)\n a.close()\n # Now, read some frames, go back, and compare buffers\n # (check whence == 1 == SEEK_CUR)\n a = Sndfile(ofilename, 'r')\n a.read_frames(buffsize)\n buff = a.read_frames(buffsize)\n a.seek(-buffsize, 1)\n buff2 = a.read_frames(buffsize)\n assert_array_equal(buff, buff2)\n a.close()\n # Now, read some frames, go back, and compare buffers\n # (check whence == 2 == SEEK_END)\n a = Sndfile(ofilename, 'r')\n buff = a.read_frames(nframes)\n a.seek(-buffsize, 2)\n buff2 = a.read_frames(buffsize)\n assert_array_equal(buff[-buffsize:], buff2)\n def test_rw(self):\n \"\"\"Test read/write pointers for seek.\"\"\"\n ofilename = join(TEST_DATA_DIR, 'test.wav')\n", "answers": [" rfd, fd, cfilename = open_tmp_file('rwseektest.wav')"], "length": 844, "dataset": "lcc", "language": "python", "all_classes": null, "_id": "04429037d9380b6e9c3f7b2070992a5af10745895025113c", "answer_prefix": "Next line of code:\n", "task": "lcc", "max_new_tokens": 84}, "target": "[\" rfd, fd, cfilename = open_tmp_file('rwseektest.wav')\"]", "arguments": {"gen_args_0": {"arg_0": "<|im_start|>user\nPlease complete the code given below. \nPlease complete the code given below. \n#! /usr/bin/env python\n# Last Change: Sun Dec 14 07:00 PM 2008 J\n\"\"\"Test for the sndfile class.\"\"\"\nfrom os.path import join, dirname\nimport os\nimport sys\nfrom numpy.testing import TestCase, assert_array_equal, dec\nimport numpy as np\nfrom audiolab import Sndfile, Format, available_encodings, available_file_formats\nfrom testcommon import open_tmp_file, close_tmp_file, TEST_DATA_DIR\n_DTYPE_TO_ENC = {np.float64 : 'float64', np.float32: 'float32', \n np.int32: 'pcm32', np.int16: 'pcm16'}\n# XXX: there is a lot to refactor here\nclass TestSndfile(TestCase):\n def test_basic_io(self):\n \"\"\" Check open, close and basic read/write\"\"\"\n # dirty !\n ofilename = join(TEST_DATA_DIR, 'test.wav')\n rfd, fd, cfilename = open_tmp_file('pysndfiletest.wav')\n try:\n nbuff = 22050\n # Open the test file for reading\n a = Sndfile(ofilename, 'r')\n nframes = a.nframes\n # Open the copy file for writing\n format = Format('wav', 'pcm16')\n b = Sndfile(fd, 'w', format, a.channels, a.samplerate)\n # Copy the data\n for i in range(nframes / nbuff):\n tmpa = a.read_frames(nbuff)\n assert tmpa.dtype == np.float\n b.write_frames(tmpa)\n nrem = nframes % nbuff\n tmpa = a.read_frames(nrem)\n assert tmpa.dtype == np.float\n b.write_frames(tmpa)\n a.close()\n b.close()\n finally:\n close_tmp_file(rfd, cfilename)\n @dec.skipif(sys.platform=='win32', \n \"Not testing opening by fd because does not work on win32\")\n def test_basic_io_fd(self):\n \"\"\" Check open from fd works\"\"\"\n ofilename = join(TEST_DATA_DIR, 'test.wav')\n fd = os.open(ofilename, os.O_RDONLY)\n hdl = Sndfile(fd, 'r')\n hdl.close()\n def test_raw(self):\n rawname = join(TEST_DATA_DIR, 'test.raw')\n format = Format('raw', 'pcm16', 'little')\n a = Sndfile(rawname, 'r', format, 1, 11025)\n assert a.nframes == 11290\n a.close()\n def test_float64(self):\n \"\"\"Check float64 write/read works\"\"\"\n self._test_read_write(np.float64)\n def test_float32(self):\n \"\"\"Check float32 write/read works\"\"\"\n self._test_read_write(np.float32)\n def test_int32(self):\n \"\"\"Check 32 bits pcm write/read works\"\"\"\n self._test_read_write(np.int32)\n def test_int16(self):\n \"\"\"Check 16 bits pcm write/read works\"\"\"\n self._test_read_write(np.int16)\n def _test_read_write(self, dtype):\n # dirty !\n ofilename = join(TEST_DATA_DIR, 'test.wav')\n rfd, fd, cfilename = open_tmp_file('pysndfiletest.wav')\n try:\n nbuff = 22050\n # Open the test file for reading\n a = Sndfile(ofilename, 'r')\n nframes = a.nframes\n # Open the copy file for writing\n format = Format('wav', _DTYPE_TO_ENC[dtype])\n b = Sndfile(fd, 'w', format, a.channels, a.samplerate)\n # Copy the data in the wav file\n for i in range(nframes / nbuff):\n tmpa = a.read_frames(nbuff, dtype=dtype)\n assert tmpa.dtype == dtype\n b.write_frames(tmpa)\n nrem = nframes % nbuff\n tmpa = a.read_frames(nrem)\n b.write_frames(tmpa)\n a.close()\n b.close()\n # Now, reopen both files in for reading, and check data are\n # the same\n a = Sndfile(ofilename, 'r')\n b = Sndfile(cfilename, 'r')\n for i in range(nframes / nbuff):\n tmpa = a.read_frames(nbuff, dtype=dtype)\n tmpb = b.read_frames(nbuff, dtype=dtype)\n assert_array_equal(tmpa, tmpb)\n a.close()\n b.close()\n finally:\n close_tmp_file(rfd, cfilename)\n #def test_supported_features(self):\n # for i in available_file_formats():\n # print \"Available encodings for format %s are : \" % i\n # for j in available_encodings(i):\n # print '\\t%s' % j\n def test_short_io(self):\n self._test_int_io(np.short)\n def test_int32_io(self):\n self._test_int_io(np.int32)\n def _test_int_io(self, dt):\n # TODO: check if neg or pos value is the highest in abs\n rfd, fd, cfilename = open_tmp_file('pysndfiletest.wav')\n try:\n # Use almost full possible range possible for the given data-type\n nb = 2 ** (8 * np.dtype(dt).itemsize - 3)\n fs = 22050\n nbuff = fs\n a = np.random.random_integers(-nb, nb, nbuff)\n a = a.astype(dt)\n # Open the file for writing\n format = Format('wav', _DTYPE_TO_ENC[dt])\n b = Sndfile(fd, 'w', format, 1, fs)\n b.write_frames(a)\n b.close()\n b = Sndfile(cfilename, 'r')\n read_a = b.read_frames(nbuff, dtype=dt)\n b.close()\n assert_array_equal(a, read_a)\n finally:\n close_tmp_file(rfd, cfilename)\n def test_mismatch(self):\n \"\"\"Check for bad arguments.\"\"\"\n # This test open a file for writing, but with bad args (channels and\n # nframes inverted)\n rfd, fd, cfilename = open_tmp_file('pysndfiletest.wav')\n try:\n # Open the file for writing\n format = Format('wav', 'pcm16')\n try:\n b = Sndfile(fd, 'w', format, channels=22000, samplerate=1)\n raise AssertionError(\"Try to open a file with more than 256 \"\\\n \"channels, this should not succeed !\")\n except ValueError, e:\n pass\n finally:\n close_tmp_file(rfd, cfilename)\n def test_bigframes(self):\n \"\"\" Try to seek really far.\"\"\"\n rawname = join(TEST_DATA_DIR, 'test.wav')\n a = Sndfile(rawname, 'r')\n try:\n try:\n a.seek(2 ** 60)\n raise Exception, \\\n \"Seek really succeded ! This should not happen\"\n except IOError, e:\n pass\n finally:\n a.close()\n def test_float_frames(self):\n \"\"\" Check nframes can be a float\"\"\"\n rfd, fd, cfilename = open_tmp_file('pysndfiletest.wav')\n try:\n # Open the file for writing\n format = Format('wav', 'pcm16')\n a = Sndfile(fd, 'rw', format, channels=1, samplerate=22050)\n tmp = np.random.random_integers(-100, 100, 1000)\n tmp = tmp.astype(np.short)\n a.write_frames(tmp)\n a.seek(0)\n a.sync()\n ctmp = a.read_frames(1e2, dtype=np.short)\n a.close()\n finally:\n close_tmp_file(rfd, cfilename)\n def test_nofile(self):\n \"\"\" Check the failure when opening a non existing file.\"\"\"\n try:\n f = Sndfile(\"floupi.wav\", \"r\")\n raise AssertionError(\"call to non existing file should not succeed\")\n except IOError:\n pass\n except Exception, e:\n raise AssertionError(\"opening non existing file should raise\" \\\n \" a IOError exception, got %s instead\" %\n e.__class__)\nclass TestSeek(TestCase):\n def test_simple(self):\n ofilename = join(TEST_DATA_DIR, 'test.wav')\n # Open the test file for reading\n a = Sndfile(ofilename, 'r')\n nframes = a.nframes\n buffsize = 1024\n buffsize = min(nframes, buffsize)\n # First, read some frames, go back, and compare buffers\n buff = a.read_frames(buffsize)\n a.seek(0)\n buff2 = a.read_frames(buffsize)\n assert_array_equal(buff, buff2)\n a.close()\n # Now, read some frames, go back, and compare buffers\n # (check whence == 1 == SEEK_CUR)\n a = Sndfile(ofilename, 'r')\n a.read_frames(buffsize)\n buff = a.read_frames(buffsize)\n a.seek(-buffsize, 1)\n buff2 = a.read_frames(buffsize)\n assert_array_equal(buff, buff2)\n a.close()\n # Now, read some frames, go back, and compare buffers\n # (check whence == 2 == SEEK_END)\n a = Sndfile(ofilename, 'r')\n buff = a.read_frames(nframes)\n a.seek(-buffsize, 2)\n buff2 = a.read_frames(buffsize)\n assert_array_equal(buff[-buffsize:], buff2)\n def test_rw(self):\n \"\"\"Test read/write pointers for seek.\"\"\"\n ofilename = join(TEST_DATA_DIR, 'test.wav')\nNext line of code:<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n", "arg_1": {"max_gen_toks": 64, "temperature": 1.0, "do_sample": false, "until": []}}}, "resps": [["Here is the continuation of the `TestSeek` class, completing the `test_rw` method:\n\n```python\n def test_rw(self):\n \"\"\"Test read/write pointers for seek.\"\"\"\n ofilename = join(TEST_DATA_DIR, 'test.wav')\n # Open the test file for reading and writing\n a"]], "filtered_resps": ["Here is the continuation of the `TestSeek` class, completing the `test_rw` method:\n\n```python\n def test_rw(self):\n \"\"\"Test read/write pointers for seek.\"\"\"\n ofilename = join(TEST_DATA_DIR, 'test.wav')\n # Open the test file for reading and writing\n a"], "filter": "none", "metrics": ["score", "code_sim_score"], "doc_hash": "3f14022a6c9a488ff8fd50edd3888ce73b081afa9d922ec0c947cc900ad0b79b", "prompt_hash": "d1c54958777b88a4233dcf92ad5978d5da169516b3fe39c88525884113c64207", "target_hash": "94ff788e2c5e98caf756b06c75ef6e0930eb93cc90deda4fd205e1049979bce0", "score": 0.0, "code_sim_score": 0.0}
{"doc_id": 3, "doc": {"question": "", "context": "Please complete the code given below. \n#!/usr/bin/env python\nfrom apps.webdriver_testing.pages.site_pages import UnisubsPage\nfrom urlparse import urlsplit\nclass VideoPage(UnisubsPage):\n \"\"\"\n Video Page contains the common elements in the video page.\n \"\"\"\n _URL = \"videos/%s/info/\" # %s is the unique onsite video id\n _VIDEO_TITLE = \".main-title a\"\n _SPEAKER_NAME = \"div.content div div > h4\"\n _LOCATION = \"div.content div div h4:nth-child(2)\"\n _DESCRIPTION = \"div#description\"\n _EMBEDDED_VIDEO = \"div.unisubs-widget div.unisubs-videoTab-container\"\n _SUBTITLE_MENU = \"a.unisubs-subtitleMeLink span.unisubs-tabTextchoose\"\n _LIKE_FACEBOOK = \"li.unisubs-facebook-like button\"\n _POST_FACEBOOK = \"a.facebook\"\n _POST_TWITTER = \"a.twittter\"\n _EMAIL_FRIENDS = \"a.email\"\n _FOLLOW = \"button.follow-button\"\n #FOLLOW CONFIRMATION\n _UNFOLLOW_ALL = 'input#unfollow-all-languages-button'\n _SUBTITLES_OK = 'input#popup_ok'\n _EMBED_HELP = \"div.unisubs-share h3 a.embed_options_link\"\n _EMBED_CODE = (\"div#embed-modal.modal div.modal-body form fieldset \"\n \"textarea\")\n #TOP TABS\n _URLS_TAB = 'href=\"?tab=urls\"]'\n _VIDEO_TAB = 'a[href=\"?tab=video\"]'\n _COMMENTS_TAB = 'a[href=\"?tab=comments\"]'\n _ACTIVITY_TAB = 'a[href=\"?tab=activity\"]'\n _ADD_SUBTITLES = \"a.add_subtitles\"\n #VIDEO SIDE SECTION\n _INFO = \"ul#video-menu.left_nav li:nth-child(1) > a\"\n _ADD_TRANSLATION = \"li.contribute a#add_translation\"\n _UPLOAD_SUBTITLES = \"a#upload-subtitles-link\"\n #SUBTITLES_SIDE_SECTION\n _SUB_LANGUAGES = \"ul#subtitles-menu li\"\n _STATUS_TAGS = \"span.tags\"\n #TEAM_SIDE_SECTION\n _ADD_TO_TEAM_PULLDOWN = (\"ul#moderation-menu.left_nav li div.sort_button \"\n \"div.arrow\")\n _TEAM_LINK = (\"ul#moderation-menu.left_nav li div.sort_button ul li \"\n \"a[href*='%s']\")\n #ADMIN_SIDE_SECTION\n _DEBUG_INFO = \"\"\n _EDIT = \"\"\n #UPLOAD SUBTITLES DIALOG\n _SELECT_LANGUAGE = 'select#id_language_code'\n _TRANSLATE_FROM = 'select#id_from_language_code'\n _PRIMARY_AUDIO = 'select#id_primary_audio_language_code'\n _SUBTITLES_FILE = 'input#subtitles-file-field'\n _IS_COMPLETE = 'input#updload-subtitles-form-is_complete' #checked default\n _UPLOAD_SUBMIT = 'form#upload-subtitles-form button.green_button'\n _FEEDBACK_MESSAGE = 'p.feedback-message'\n _CLOSE = 'div#upload_subs-div a.close'\n UPLOAD_SUCCESS_TEXT = ('Thank you for uploading. It may take a minute or '\n 'so for your subtitles to appear.')\n #TAB FIELDS\n _COMMENTS_BOX = 'textarea#id_comment_form_content'\n _ACTIVITY_LIST = 'ul.activity li p' \n def open_video_page(self, video_id):\n self.open_page(self._URL % video_id)\n def open_video_activity(self, video_id):\n self.open_video_page(video_id)\n self.click_by_css(self._ACTIVITY_TAB)\n def video_title(self):\n return self.get_text_by_css(self._VIDEO_TITLE)\n def add_translation(self):\n self.click_by_css(self._ADD_TRANSLATION)\n def upload_subtitles(self, \n sub_lang, \n sub_file,\n audio_lang = None,\n translated_from = None, \n is_complete = True):\n #Open the dialog\n self.wait_for_element_visible(self._UPLOAD_SUBTITLES)\n self.click_by_css(self._UPLOAD_SUBTITLES)\n #Choose the language\n self.wait_for_element_visible(self._SELECT_LANGUAGE)\n self.select_option_by_text(self._SELECT_LANGUAGE, sub_lang)\n #Set the audio language\n if audio_lang:\n self.select_option_by_text(self._PRIMARY_AUDIO, audio_lang)\n #Set the translation_from field\n if translated_from:\n self.select_option_by_text(self._TRANSLATE_FROM, translated_from)\n #Input the subtitle file\n self.type_by_css(self._SUBTITLES_FILE, sub_file)\n #Set complete\n if not is_complete:\n self.click_by_css(self._IS_COMPLETE)\n #Start the upload\n self.wait_for_element_present(self._UPLOAD_SUBMIT)\n self.click_by_css(self._UPLOAD_SUBMIT)\n #Get the the response message\n self.wait_for_element_present(self._FEEDBACK_MESSAGE, wait_time=20)\n message_text = self.get_text_by_css(self._FEEDBACK_MESSAGE)\n #Close the dialog\n self.click_by_css(self._CLOSE)\n self.wait_for_element_not_visible(self._CLOSE)\n return message_text\n def open_info_page(self):\n self.click_by_css(self._INFO)\n def add_video_to_team(self, team_name):\n self.click_by_css(self._ADD_TO_TEAM_PULLDOWN)\n self.click_by_css(self._TEAM_LINK % team_name)\n def video_id(self):\n page_url = self.browser.current_url\n url_parts = urlsplit(page_url).path\n urlfrag = url_parts.split('/')[3]\n return urlfrag\n def description_text(self):\n return self.get_text_by_css(self._DESCRIPTION)\n def speaker_name(self):\n return self.get_text_by_css(self._SPEAKER_NAME)\n def location(self):\n return self.get_text_by_css(self._LOCATION)\n def video_embed_present(self):\n if self.is_element_present(self._EMBEDDED_VIDEO):\n return True\n def add_subtitles(self):\n self.click_by_css(self._ADD_SUBTITLES)\n def team_slug(self, slug):\n \"\"\"Return true if the team stub is linked on the video page.\n \"\"\"\n team_link = \"a[href*='/teams/%s/']\" % slug\n if self.is_element_present(team_link):\n return True\n def feature_video(self):\n self.click_link_text('Feature video')\n def unfeature_video(self):\n self.click_link_text('Unfeature video')\n def displays_subtitle_me(self):\n return self.is_element_visible(self._SUBTITLE_MENU)\n def click_subtitle_me(self):\n self.click_by_css(self._SUBTITLE_MENU)\n def displays_add_subtitles(self):\n return self.is_element_visible(self._ADD_SUBTITLES)\n def displays_add_translation(self):\n return self.is_element_visible(self._ADD_TRANSLATION)\n def displays_upload_subtitles(self):\n return self.is_element_visible(self._UPLOAD_SUBTITLES)\n def follow_text(self):\n return self.get_text_by_css(self._FOLLOW)\n def toggle_follow(self, lang=False):\n self.click_by_css(self._FOLLOW)\n if lang:\n self.click_by_css(self._SUBTITLES_OK)\n else:\n self.click_by_css(self._UNFOLLOW_ALL)\n def subtitle_languages(self):\n langs = []\n els = self.get_elements_list(self._SUB_LANGUAGES + \" a\")\n for el in els:\n langs.append(el.text)\n return langs\n def language_status(self, language):\n els = self.get_elements_list(self._SUB_LANGUAGES)\n for el in els:\n e = el.find_element_by_css_selector(\"a\")\n self.logger.info(e.text)\n", "answers": [" if e.text == language:"], "length": 462, "dataset": "lcc", "language": "python", "all_classes": null, "_id": "9bc1f81e1a4c4b44da11ffc093a0c9fecbe5f99e4eff3aa5", "answer_prefix": "Next line of code:\n", "task": "lcc", "max_new_tokens": 84}, "target": "[' if e.text == language:']", "arguments": {"gen_args_0": {"arg_0": "<|im_start|>user\nPlease complete the code given below. \nPlease complete the code given below. \n#!/usr/bin/env python\nfrom apps.webdriver_testing.pages.site_pages import UnisubsPage\nfrom urlparse import urlsplit\nclass VideoPage(UnisubsPage):\n \"\"\"\n Video Page contains the common elements in the video page.\n \"\"\"\n _URL = \"videos/%s/info/\" # %s is the unique onsite video id\n _VIDEO_TITLE = \".main-title a\"\n _SPEAKER_NAME = \"div.content div div > h4\"\n _LOCATION = \"div.content div div h4:nth-child(2)\"\n _DESCRIPTION = \"div#description\"\n _EMBEDDED_VIDEO = \"div.unisubs-widget div.unisubs-videoTab-container\"\n _SUBTITLE_MENU = \"a.unisubs-subtitleMeLink span.unisubs-tabTextchoose\"\n _LIKE_FACEBOOK = \"li.unisubs-facebook-like button\"\n _POST_FACEBOOK = \"a.facebook\"\n _POST_TWITTER = \"a.twittter\"\n _EMAIL_FRIENDS = \"a.email\"\n _FOLLOW = \"button.follow-button\"\n #FOLLOW CONFIRMATION\n _UNFOLLOW_ALL = 'input#unfollow-all-languages-button'\n _SUBTITLES_OK = 'input#popup_ok'\n _EMBED_HELP = \"div.unisubs-share h3 a.embed_options_link\"\n _EMBED_CODE = (\"div#embed-modal.modal div.modal-body form fieldset \"\n \"textarea\")\n #TOP TABS\n _URLS_TAB = 'href=\"?tab=urls\"]'\n _VIDEO_TAB = 'a[href=\"?tab=video\"]'\n _COMMENTS_TAB = 'a[href=\"?tab=comments\"]'\n _ACTIVITY_TAB = 'a[href=\"?tab=activity\"]'\n _ADD_SUBTITLES = \"a.add_subtitles\"\n #VIDEO SIDE SECTION\n _INFO = \"ul#video-menu.left_nav li:nth-child(1) > a\"\n _ADD_TRANSLATION = \"li.contribute a#add_translation\"\n _UPLOAD_SUBTITLES = \"a#upload-subtitles-link\"\n #SUBTITLES_SIDE_SECTION\n _SUB_LANGUAGES = \"ul#subtitles-menu li\"\n _STATUS_TAGS = \"span.tags\"\n #TEAM_SIDE_SECTION\n _ADD_TO_TEAM_PULLDOWN = (\"ul#moderation-menu.left_nav li div.sort_button \"\n \"div.arrow\")\n _TEAM_LINK = (\"ul#moderation-menu.left_nav li div.sort_button ul li \"\n \"a[href*='%s']\")\n #ADMIN_SIDE_SECTION\n _DEBUG_INFO = \"\"\n _EDIT = \"\"\n #UPLOAD SUBTITLES DIALOG\n _SELECT_LANGUAGE = 'select#id_language_code'\n _TRANSLATE_FROM = 'select#id_from_language_code'\n _PRIMARY_AUDIO = 'select#id_primary_audio_language_code'\n _SUBTITLES_FILE = 'input#subtitles-file-field'\n _IS_COMPLETE = 'input#updload-subtitles-form-is_complete' #checked default\n _UPLOAD_SUBMIT = 'form#upload-subtitles-form button.green_button'\n _FEEDBACK_MESSAGE = 'p.feedback-message'\n _CLOSE = 'div#upload_subs-div a.close'\n UPLOAD_SUCCESS_TEXT = ('Thank you for uploading. It may take a minute or '\n 'so for your subtitles to appear.')\n #TAB FIELDS\n _COMMENTS_BOX = 'textarea#id_comment_form_content'\n _ACTIVITY_LIST = 'ul.activity li p' \n def open_video_page(self, video_id):\n self.open_page(self._URL % video_id)\n def open_video_activity(self, video_id):\n self.open_video_page(video_id)\n self.click_by_css(self._ACTIVITY_TAB)\n def video_title(self):\n return self.get_text_by_css(self._VIDEO_TITLE)\n def add_translation(self):\n self.click_by_css(self._ADD_TRANSLATION)\n def upload_subtitles(self, \n sub_lang, \n sub_file,\n audio_lang = None,\n translated_from = None, \n is_complete = True):\n #Open the dialog\n self.wait_for_element_visible(self._UPLOAD_SUBTITLES)\n self.click_by_css(self._UPLOAD_SUBTITLES)\n #Choose the language\n self.wait_for_element_visible(self._SELECT_LANGUAGE)\n self.select_option_by_text(self._SELECT_LANGUAGE, sub_lang)\n #Set the audio language\n if audio_lang:\n self.select_option_by_text(self._PRIMARY_AUDIO, audio_lang)\n #Set the translation_from field\n if translated_from:\n self.select_option_by_text(self._TRANSLATE_FROM, translated_from)\n #Input the subtitle file\n self.type_by_css(self._SUBTITLES_FILE, sub_file)\n #Set complete\n if not is_complete:\n self.click_by_css(self._IS_COMPLETE)\n #Start the upload\n self.wait_for_element_present(self._UPLOAD_SUBMIT)\n self.click_by_css(self._UPLOAD_SUBMIT)\n #Get the the response message\n self.wait_for_element_present(self._FEEDBACK_MESSAGE, wait_time=20)\n message_text = self.get_text_by_css(self._FEEDBACK_MESSAGE)\n #Close the dialog\n self.click_by_css(self._CLOSE)\n self.wait_for_element_not_visible(self._CLOSE)\n return message_text\n def open_info_page(self):\n self.click_by_css(self._INFO)\n def add_video_to_team(self, team_name):\n self.click_by_css(self._ADD_TO_TEAM_PULLDOWN)\n self.click_by_css(self._TEAM_LINK % team_name)\n def video_id(self):\n page_url = self.browser.current_url\n url_parts = urlsplit(page_url).path\n urlfrag = url_parts.split('/')[3]\n return urlfrag\n def description_text(self):\n return self.get_text_by_css(self._DESCRIPTION)\n def speaker_name(self):\n return self.get_text_by_css(self._SPEAKER_NAME)\n def location(self):\n return self.get_text_by_css(self._LOCATION)\n def video_embed_present(self):\n if self.is_element_present(self._EMBEDDED_VIDEO):\n return True\n def add_subtitles(self):\n self.click_by_css(self._ADD_SUBTITLES)\n def team_slug(self, slug):\n \"\"\"Return true if the team stub is linked on the video page.\n \"\"\"\n team_link = \"a[href*='/teams/%s/']\" % slug\n if self.is_element_present(team_link):\n return True\n def feature_video(self):\n self.click_link_text('Feature video')\n def unfeature_video(self):\n self.click_link_text('Unfeature video')\n def displays_subtitle_me(self):\n return self.is_element_visible(self._SUBTITLE_MENU)\n def click_subtitle_me(self):\n self.click_by_css(self._SUBTITLE_MENU)\n def displays_add_subtitles(self):\n return self.is_element_visible(self._ADD_SUBTITLES)\n def displays_add_translation(self):\n return self.is_element_visible(self._ADD_TRANSLATION)\n def displays_upload_subtitles(self):\n return self.is_element_visible(self._UPLOAD_SUBTITLES)\n def follow_text(self):\n return self.get_text_by_css(self._FOLLOW)\n def toggle_follow(self, lang=False):\n self.click_by_css(self._FOLLOW)\n if lang:\n self.click_by_css(self._SUBTITLES_OK)\n else:\n self.click_by_css(self._UNFOLLOW_ALL)\n def subtitle_languages(self):\n langs = []\n els = self.get_elements_list(self._SUB_LANGUAGES + \" a\")\n for el in els:\n langs.append(el.text)\n return langs\n def language_status(self, language):\n els = self.get_elements_list(self._SUB_LANGUAGES)\n for el in els:\n e = el.find_element_by_css_selector(\"a\")\n self.logger.info(e.text)\nNext line of code:<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n", "arg_1": {"max_gen_toks": 64, "temperature": 1.0, "do_sample": false, "until": []}}}, "resps": [["The code you've provided is a Python class that represents a **Video Page** in a web application, likely part of a test suite using **Selenium** and **Unisubs** (a subtitle management system). The class contains methods for interacting with elements on the video page, such as uploading subtitles, following/un"]], "filtered_resps": ["The code you've provided is a Python class that represents a **Video Page** in a web application, likely part of a test suite using **Selenium** and **Unisubs** (a subtitle management system). The class contains methods for interacting with elements on the video page, such as uploading subtitles, following/un"], "filter": "none", "metrics": ["score", "code_sim_score"], "doc_hash": "fbecd2ab2496c502c0ffc51d03dfc672856c197e30c639ef7fa2bf410d98d5dc", "prompt_hash": "8dd27a0c885d31bbb30da0a6ebc8249c8a2cf9303842fc9bc547f260bce7a74f", "target_hash": "853d05655542db53a2157d0382bd69f08a656ec7bca3ec35b0439a17fd2941d4", "score": 0.08, "code_sim_score": 0.08}